The cardinality sort is also a stable internal sort.
Because its implementation is based on internal use of a stable sort implementation, the overall cardinality is stable, and the time complexity is O (n).
As an example:
Now we're going to sort some 3 (multiple) digits, and if you say you're right, then you're naïve, because then it turns into O (NLGN) or O (N2).
How can you reduce the complexity of time into O (n)?
That's the sort of linear time that's going to be used, as in the count of the previous article.
The cardinality sort is sorted by counting sort. Because the count sort is a stable sort, the ordered size order is consistent with the sort order of the previous round.
Let me give you an example:
| Before sorting |
After the first sort |
After the second order |
After the Third order |
Results of sorting |
| 331 |
420 |
410 |
315 |
315 |
| 315 |
410 |
315 |
331 |
331 |
| 420 |
331 |
420 |
410 |
410 |
| 410 |
315 |
331 |
420 |
420 |
The order of the ordered results is based on the results of the previous comparison: from the table above, we can see that the comparison is from single digit to highest;
Please see:
1, the second sort you will find: 3,151 straight under 331, 4,101 straight under 420.
2, the Third order will be the overall order.
Radixsort (int [] a) {
For i = 1 to n-1//number of digits from single digit to highest bit sorted sequentially
Countingsort (B[i])//Count sort
}
Algorithm--Sort the cardinal sort