Pigeonhole sorting, also known as count sort (not to be confused with counting sort), is a sorting algorithm that is suitable for sorting lists of elements where the number of elements (n) and the number of possible key values (N) are approximately the same. It requires Θ(n + N) time.
The pigeonhole algorithm works as follows:
For example, suppose we were sorting these value pairs by their first element:
For each value between 3 and 8 we set up a...
more
Pigeonhole sorting, also known as count sort (not to be confused with counting sort), is a sorting algorithm that is suitable for sorting lists of elements where the number of elements (n) and the number of possible key values (N) are approximately the same. It requires Θ(n + N) time.
The pigeonhole algorithm works as follows:
For example, suppose we were sorting these value pairs by their first element:
For each value between 3 and 8 we set up a pigeonhole, then move each element to its pigeonhole:
We then iterate over the pigeonhole array in order and move them back to the original list.
The difference between pigeonhole sort and counting sort is that in counting sort, the auxiliary array does not contain lists of input elements, only counts:
Using this information we can perform a series of exchanges on the input array that puts it in order, moving items only once. Pigeonhole sort, in contrast, moves items twice: once onto the pigeonhole/bucket array and again onto the destination...
less