The Pigeon Nest Sort, also known as Cardinal classification, is a sort algorithm with time complexity (Theta (n)) that is the most efficient when it is unavoidable to traverse each element and sort. However, it is useful only if the difference (or the number of values that can be mapped in the difference) is sorted in a small range. When multiple unequal elements are involved and the elements are placed in the same "pigeon nest", the efficiency of the algorithm is reduced. In order to be simple and keep the pigeon nest sorted in different situations, such as two elements that end in the same bucket must be equal.
We generally rarely use pigeon nests for sorting because it is rarely available in flexibility, simplicity, and especially speed over other sorting algorithms. In fact, the bucket sort is more practical than the pigeon-nest sort. A more famous variant of the pigeon nest sort is the tally sort, which only applies to very limited topics, and this algorithm is famous in programming pearls as an example of a method for solving a very limited set of problems. Clearly, a quick sort can be used as a sort of pigeon nest with only two (in some cases three) "Pigeon nests".
algorithm Efficiency
Worst time complexity: O (N+n)
Best time complexity: O (N+n)
Average time complexity: O (N+n)
The worst of the space complexity: O (N*n)
Algorithm Analysis 1. Given a sorted array, create an alternate array (pigeon nest) and initialize the element to 0, and the index of the alternate array is the value of the array to be sorted.
2. Place the value of the array to be sorted into the "pigeon Nest" (that is, the index used as an alternate array).
3. The values in the pigeon nest are then sent back to the sorted array.
Pigeon Nest Sort///</summary>///<param name= "unsorted" > Backlog array </param>///<param na Me= "MaxNumber" > Maximum number of arrays to be ranked, if specified </param>///<returns></returns> static int[] Pogeon
_sort (int[] unsorted, int maxnumber = ten) {int[] Pogeonhole = new Int[maxnumber + 1];
foreach (var item in unsorted) {pogeonhole[item]++;
return pogeonhole; * * POGEONHOLE[10] = 4;
The implication is that there are 4 10 occurrences in the array to be ranked, the same as other/} static void Main (string[] args) {
int[] x = {99, 65, 24, 47, 47, 50, 99, 88, 66, 33, 66, 67, 31, 18, 24};
var sorted = Pogeon_sort (x, 99); for (int i = 0; i < sorted. Length; i++) {for (int j = 0; J < Sorted[i]; J +) {CONSOLE.WR
Iteline (i);
}} console.readline (); }