Algorithm--Sort the cardinal sort

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.