Data structure--sort (bottom)--base sort

Source: Internet
Author: User

Base sort

The previous algorithm has a PR feature, which is based on the comparison size to sort. Worst case Nlogn, besides comparison, is doing something else.

Bucket sort

Let's say we have n students whose grades are integers between 0 and 100 (so there's a different score for m=101). How do I sort students by their grades in linear time ?

Build 101 Barrels

void int N) {  count[] initialization;     while (read 1 students ' grades grade)      Insert the student into the list of Count[grade];     for (i=0; i<m; i++ ) {      if  (Count[i])         outputs the entire count[i] linked list;}   }

The complexity of Time is

What if M "n"? Below

Base sort

Base sort is an upgraded version of bucket ordering

If it is a bucket, you have to build 1001 barrels, but only 10 numbers, it's not worth it.

The binary cardinality is 2, the decimal base is 10, and the secondary bit is the first.

Set the number of elements is n, the integer into the B,LSD (secondary bit first) the number of times is P, then the worst time complexity is a total of p lying sort.

If the number of buckets is very small, then the complexity of time is the antecedent complexity.

Purpose of cardinality sorting, handling multi-keyword sorting

Sort multiple Keywords

The priority of the theme is not the second priority. Sub-priority does not need to be sorted at all. The second priority here is faster than the theme,

But is LSD faster than MSD at any time?

Data structure--sort (bottom)--base 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.