You are on page 1of 2

BUCKET SORT/RADIX SORT

Bucket sort, or bin sort, is a sorting algorithm that works by distributing the elements of
an array into a number of buckets. Each bucket is then sorted individually, either using a
different sorting algorithm, or by recursively applying the bucket sorting algorithm.
Bucket sort can be implemented with comparisons and therefore can also be considered a
comparison sort algorithm. The computational complexity depends on the algorithm used
to sort each bucket, the number of buckets to use, and whether the input is uniformly
distributed.

1) Bucket Sort is also known as bin sort because you create bins or buckets to sort inputs.

2) Bucket sort is only useful when the input is uniformly distributed over a range like
coins, numbers 1 to 100 etc.

3) We can use a linked list or array as a bucket. The choice of data structure will affect
the insertion time e.g. if we use linked list then adding on the head could take O(1) time.
You can also use hash tables as buckets.

4) The bucket sort is one of the rare O(n) sorting algorithm i.e. time complexity of Bucket
sort is the liner in best and average case and not NLogN like Quicksort or Mergesort.

5) Bucket sort is not a stable sorting algorithm because in a stable algorithm if two input
is same they retain their place in sorted order and in the bucket it depends upon how we
sort the individual bucket. Though, bucket sort can be made stable, known as radix sort.

6) We can sort the elements inside individual buckets either by recursively calling the
bucket sort or using a separate sorting algorithm like insertion sort, bubble sort, or
quicksort.

7) Is bucket sort an in-place sorting algorithm? No, it's not an in-place sorting algorithm.
The whole idea is that input sorts themselves as they are moved to the buckets. In the
worst of the good cases (sequential values, but no repetition) the additional space needed
is as big as the original array.

8) The worst case complexity of bucket sort, when all elements will end up in the same
bucket is O(n^2) because then it has to be sorted by a different sorting algorithm.

9) The space complexity of bucket sort is O(n) because even to sort sequential values,
without repetition, we need an array as big as the original array.
Algorithm for Bucket Sort

bucketSort()

create N buckets each of which can hold a range of values

for all the buckets

initialize each bucket with 0 values

for all the buckets

put elements into buckets matching the range

for all the buckets

sort elements in each bucket

gather elements from each bucket

end bucketSort

You might also like