Chapter 1 basic concepts and categories of sorting

Source: Internet
Author: User

1. Definition of sorting: assume that the sequence Containing n records is {r1, r2 ,......, rn}, whose corresponding keywords are {k1, k2 ,......, kn}, must be determined 1, 2 ,......, an array of n: p1, p2 ,......, pn, so that the corresponding keyword meets kp1 <= kp2 <= ...... <= kpn non-incrementing or non-decreasing) relationship, even if the obtained sequence becomes a sequence ordered by keywords {rp1, rp2 ,......, rpn}, such an operation is called sorting.

2. Stability of sorting: Assuming the keyword ki = kj (I! = J), and the ri is ahead of rj in the sequence before sorting. If the ri is still ahead of rj after sorting, the sorting method used is stable. Otherwise, if rj leads the sorted sequence to ri, the method used is unstable. In short, Xiao Ming and Xiao Fang have the same total score. Xiao Ming ranks before Xiao Fang, while Xiao Ming also ranks before Xiao Fang. The Sorting Algorithm is stable, otherwise, the algorithm is unstable.

3. Inner sorting and external sorting: All records to be sorted are stored in the memory during the entire sorting process. External sorting is because the number of sorting records is too large and cannot be stored in the memory at the same time. The entire sorting process needs to exchange data multiple times between internal and external.

The internal sorting is mainly affected by three factors.

1) time performance. In the internal sorting, two types of operations are performed: Comparison and moving. In short, we should minimize the number of comparisons and minimize the number of moves in the sorting process.

2) auxiliary space. Space required to store the data to be sorted and other storage space required for Algorithm Execution.

3) Complexity of algorithms. This refers to the complexity of the algorithm itself, rather than the time complexity of the algorithm. Obviously, the algorithm is too complex and affects the sorting performance.

4. Classification of sorting algorithms

1) Exchange sorting: Bubble sorting and quick sorting.

2) Insert sorting: directly insert sorting, semi-insert sorting, and Hill sorting.

3) Select sorting: simple sorting and heap sorting.

4) Merge Sorting: Merge Sorting.

 

This article is from "Li Haichuan" blog, please be sure to keep this source http://lihaichuan.blog.51cto.com/498079/1282052

Related Article

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.