SortingAnimated
Bucket Sort
Distribute into range buckets, sort each, concatenate.
Time
O(n) avg, O(n²) worst
Extra space
O(n)
Use it for
Uniformly distributed numbers.
How it works
- Spread the values over a few buckets, each covering an equal slice of the range.
- Sort each bucket on its own (insertion sort works well because buckets are small).
- Concatenate the buckets from lowest to highest.
- Fast (about O(n)) when the data is spread evenly; slow if everything lands in one bucket.
Watch it run
Loading animation…