SortingAnimated
Pigeonhole Sort
One hole per possible value; drop items in and read back.
Time
O(n + range)
Extra space
O(range)
Use it for
Range of values close to the number of items.
How it works
- A cousin of counting sort for when the range of values is about as large as the list.
- Make one "hole" for every value between the minimum and the maximum.
- Drop each item into its hole.
- Read the holes from left to right to get the sorted list.
Watch it run
Loading animation…