Bucket sort
A sorting algorithm that splits the data into buckets by range, sorts each bucket and joins them in order.
Example
Prices from 0 to 999 into 10 buckets of 100: 0 to 99, 100 to 199... Each bucket is sorted separately.
Test yourself: Bucket sort
Bucket sort
With 10 buckets for numbers between 0 and 1, 0.37 goes into the bucket from 0.3 to ___.
Each bucket covers 0.1: 0.37 lands in the 4th, from 0.3 to 0.4. 0.05 would go into the 1st.
Bucket sort
With 1 million items evenly spread into 1,000 buckets, each bucket has about ___ elements.
1,000,000 / 1,000 = 1,000. Sorting each costs about 10,000 steps; all 1,000, about 10 million in total.
Bucket sort
You split product prices into 10 buckets of 100 dollars, but 90% cost less than 100. What happens?
With 1 million products, the first bucket has 900,000: sorting it costs almost as much as sorting everything together.
0/3
â–¶ Play