Pigeonhole sorting is a sorting algorithm that is suitable for sorting lists of elements where the number of elements and the number of possible key values are approximately the same.
It requires O(n + Range) time where n is number of elements in input array and ‘Range’ is number of possible values in array.
Working of Algorithm :
- Find minimum and maximum values in array. Let the minimum and maximum values be ‘min’ and ‘max’ respectively. Also find range as ‘max-min-1’.
- Set up an array of initially empty “pigeonholes” the same size as of the range.
- Visit each element of the array and then put each element in its pigeonhole. An element arr[i] is put in hole at index arr[i] – min.
- Start the loop all over the pigeonhole array in order and put the elements from non- empty holes back into the original array.
Sorted order is : 2 3 4 6 7 8 8
Please refer complete article on Pigeonhole Sort for more details!
- Java Program for Pigeonhole Sort
- Pigeonhole Sort
- Program to sort an array of strings using Selection Sort
- Java Program for Odd-Even Sort / Brick Sort
- C/C++ Program for Odd-Even Sort / Brick Sort
- Comparison among Bubble Sort, Selection Sort and Insertion Sort
- C Program for Counting Sort
- C++ Program for Stooge Sort
- C++ Program for Comb Sort
- C Program for Bubble Sort
- C++ Program for Bubble Sort
- C++ Program for Cycle Sort
- C Program for Insertion Sort
- C++ Program for Bitonic Sort
- C++ Program for Cocktail Sort