Sorting Algorithms
Sorting Algorithms
Sorting Algorithms
bucketSort(arr[], n)
1) Create n empty buckets (Or lists).
2) Do following for every array element arr[i].
.......a) Insert arr[i] into bucket[n*array[i]]
3) Sort individual buckets using insertion sort.
4) Concatenate all sorted buckets.
Bucket sort vs counting sort vs radix sort
There are two main variants of bucket sort; one where there is a bucket
for each value, and where buckets hold several values.
Bucket sort is often seen as a generalisation of counting sort because
bucket sort with a bucket size of 1 is essentially counting sort, just
with a more complex implementation.
Another similar sort, radix sort, also distributes items into buckets.
However, they are distributed based on the individual digits within the
values themselves.
Counting sort: buckets hold only a single value
Bucket sort: buckets hold a range of values
Radix sort: buckets hold values based on digits within their values
Bubble sort _O(n2) algorithms