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

  1. A cousin of counting sort for when the range of values is about as large as the list.
  2. Make one "hole" for every value between the minimum and the maximum.
  3. Drop each item into its hole.
  4. Read the holes from left to right to get the sorted list.

Watch it run

Loading animation…