Data Structure-algorithm: Allocation sorting (base allocation sorting)

Source: Internet
Author: User

Radix sort is an improvement and promotion of Box sorting.
1. single and multi-Keyword

The keyword of any record R [I] in the file is composed of D parts.
.
If each component of the D component is an independent keyword, the file is multi-Keyword (for example, the playing card has two keywords: points and colors); otherwise, the file is single-keyword,
(0 ≤ j <D) is only one of the keywords (such as a string or a decimal integer ).
The value range of each keyword in multiple keywords is generally different. For example, there are only four types of cards and 13 types of cards. The value range of each keyword is the same.

2. Base
Set the value range of each component of a single keyword:
C0 ≤ kJ ≤ Crd-1 (0 ≤ j <D)
The number of possible values RD is called the base number.
The selection of the base number and the decomposition of the keyword vary with the type of the keyoff:
(1) If the keyword is a decimal integer, It is decomposed by number or ten equal digits. The base RD = 10, C0 = 0, C9 = 9, and D are the digits of the longest integer;
(2) If the keyword is a lowercase English string, RD = 26, CO = 'A', C25 = 'Z', and D are the maximum length of the string.

3. Basic Idea of base sorting
The basic idea of base sorting is: from low to high to kJ (j = D-1, D-2 ,..., 0) Sort boxes. In the D-box sorting, the number of required boxes is the base Rd, which is the origin of the "base sorting" name.

4. Sorting Process of base sorting
The keyword value range of the record to be sorted is an integer between 0 and 99 (, 47, 48 ). The process of sorting the keywords by base [see animation demonstration ].

5. type description andAlgorithmDescription
To ensure that the base sorting is correct, you must ensure that the sorting of the boxes except the first one is stable. Description of the corresponding types and algorithms [see the tutorial ].

6. Algorithm Analysis
If the sorting file is not given in the form of array R, but in the form of a single-chain table (this is called the chain base sorting ), you can modify the team-out and team-out functions so that the chain queue of the box does not need to allocate Node space, but uses the Node space of the original linked list. You do not need to move the records, but only need to modify the pointer. Although this saves a certain amount of time and space, the algorithm is much more complex, and the time-space complexity is not improved by an order of magnitude. You can sort the bases of a chain.

The time of base sorting is linear (that is, O (n )).
The auxiliary storage space required for base sorting is O (n + rd ).
The base sorting is stable.

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.