![]() |
VOOZH | about |
Pigeonhole Sort is a simple sorting algorithm used when the number of elements (n) and the range of possible values (k) are roughly the same. It works by placing each element into a "pigeonhole" (a slot based on its value) and then reading them back in sorted order.
1. Find range:
2. Create pigeonholes: Create an array (list) of empty pigeonholes - one for each possible value in the range.
3. Distribute elements:
4. Reconstruct sorted list: Traverse all pigeonholes in order, putting their elements back into the original list.
[2, 3, 4, 6, 7, 8, 8]
Explanation: