Data structure (41) Basic concepts and classification of sorting

Source: Internet
Author: User

First, the basic concept of sorting

Suppose that the sequence containing n records is {R1,R2,..., rn}, and its corresponding keywords are {k1,k2,..., kn}, it is necessary to determine a permutation p1,p2,..., pn,..., N, so that its corresponding keywords meet kp1≤kp2≤ ... ≤KPN a non-descending (or non-incrementing) relationship, a timely sequence called a sequential sequence of keywords {rp1,rp2,..., RPN}, which is called ordering.

  

Ii. Classification of sorting

1. Stable sequencing and unstable sequencing

    • Stable sorting: For any set of data element sequence, using some sort algorithm to sort it according to the keyword, if the same keyword's pre-and post-position relationship in the sort before and after the order of consistency, it is said that the sorting method is stable.
    • Unstable ordering: For any set of data element sequence, using some sort algorithm to sort it according to the keyword, if the same keyword's pre-and post-position relationship in the sort before and after sorting can not be consistent, it is said that the sorting method is not stable.

For example: the keyword sequence {3 (1), 4,2,3 (2), 1}, after the sorting algorithm becomes {three-way (1), 3 (2), 4}, the second order method is stable; if it becomes {-(2), 3 (1), 4}, the second-order method is unstable.

2. internal and external sorting

The different types of memory involved in the sorting process can be divided into internal and external sorts.

    • An internal sort is a sort process in which the ordered sequence is completely stored in memory, which is suitable for the ordering of a less-than-large number of data elements.
    • Out-of-order refers to the number of data elements to be sorted so that they must be stored on external storage, which needs to be exchanged more than once between the internal and external memory in order to do so, such sort is called out-of-order.

Third, the performance evaluation of ranking algorithm

    • Time performance: The time cost of the sorting algorithm is the most important indicator of its quality. The efficient in-order algorithm should be to have as few keyword comparisons as possible and as few as possible to record the number of moves.
    • Secondary space: The secondary storage space is the additional storage space needed to execute the algorithm, in addition to the storage space to be sorted.
    • Complexity of the algorithm: refers to the complexity of the algorithm itself, rather than the time complexity of the algorithm, the algorithm is too complex to affect the performance of the sorting.

  

Iv. examples of internal and external sequencing

    • Sort within: Insert sort, swap sort, select sort, and merge sort.
    • Out-of-order: Multi-balanced merge sort, permutation-select sort and optimal merge tree in disk sorting

Data structure (41) Basic concepts and classification of sorting

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.