Bucket Sort Algorithm Bucket Sort is a sorting algorithm that divides the unsorted array elements into several groups called buckets. Each bucket is then sorted by using any of the suitable sorting algorithms or recursively applying the same bucket algorithm. Finally, the sorted buckets are combined to form a final sorted array.
Bucket Sort Applications Bucket sort is used when: input is uniformly distributed over a range. there are floating point values
Working of Bucket Sort Initial array 10 buckets i.e an array of size 10 initialised with value 0
Insert the unsorted elements in the buckets according to their range After all the elements are inserted in the buckets we can use any sorting algorithm to sort these elements. Here n=10, Multiplying each value with n then assigning its bucket
Sorted elements form the buckets are now inserted into the original array by iterating through the buckets.
Bucket Sort Algorithm bucketSort ( arr [], n) Create n empty buckets (Or lists). 2) Do following for every array element arr [ i ]. ....... Insert arr [ i ] into bucket[n*array[ i ]] 3) Sort individual buckets using stable sorting algos 4) Concatenate all sorted buckets.