← Sorting Algorithms

Pigeonhole Sort

Creates one "pigeonhole" for each possible value in the range. Each element is placed directly into its hole. Ideal for small ranges with many duplicates.

Ready
Comparisons: 0 (always 0!)
Writes: 0
Range: -
Holes Used: -
Complexity: O(n + range)

How Pigeonhole Sort Works

Step 1: Find min and max to determine range.
Step 2: Create one "hole" per possible value (range = max - min + 1).
Step 3: Place each element into hole[value - min].
Step 4: Collect elements from holes in order.

Very similar to counting sort! Best when range is close to n and values repeat. Like counting sort, no comparisons are made.