Update Bucket-sort.md

pull/977/head
varun jain 2022-10-05 12:24:18 +05:30 committed by GitHub
parent 5878dc7e48
commit 2fe9fceca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -14,10 +14,11 @@ Auxiliary space: O(n)
## Steps ## Steps
Suppose there is an array **arr** with **n** distinct elements. Given an element **A**, we can find its index by counting the number of elements smaller than **A**. The bucket sort algorithm works as follows.
1. If the element is at its correct position, simply leave it as it is. 1. Assume the input array is:
2. Else, we have to find the correct position of **A** by counting the number of elements smaller than it. Another element **B** is replaced to be moved to its correct position. This process continues until we get an element at the original position of **A**. 2.
3. Else, we have to find the correct position of **A** by counting the number of elements smaller than it. Another element **B** is replaced to be moved to its correct position. This process continues until we get an element at the original position of **A**.
The above-illustrated process constitutes a cycle. Repeat this cycle for every element of the list until the list is sorted. The above-illustrated process constitutes a cycle. Repeat this cycle for every element of the list until the list is sorted.