Skip to content
StackDecode
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

  1. Spread the values over a few buckets, each covering an equal slice of the range.
  2. Sort each bucket on its own (insertion sort works well because buckets are small).
  3. Concatenate the buckets from lowest to highest.
  4. Fast (about O(n)) when the data is spread evenly; slow if everything lands in one bucket.

Watch it run

Loading animation…