Basic sorting (5): Summary of basic sorting algorithms and summary of sorting algorithms

Source: Internet
Author: User

Basic sorting (5): Summary of basic sorting algorithms and summary of sorting algorithms
Basic sorting

  • If a basic sorting algorithm is slower than data processing, such as reading and reading data, there is no need to find a faster algorithm.
  • If the sorted files are suitable for storing in memory, the sorting method is called"Internal sorting"; Sorting files from a disk is called"External sorting".DifferencesInternal sorting can easily access any element, but external sorting must access elements sequentially, at least in big data blocks.
  • Sorting programAccess Element Method: Compare with keywords and directly access the entire element to move;
  • The sorting function includes three parameters: array, left boundary of the sorted word group, and right boundary.void(Item a[], int l, int r);
  • Running time of the Sorting Algorithm: When N elements are sorted
    • Select sorting, insert sorting, Bubble sorting, and N2 Proportional;
    • Hill sorting (improved insertion sorting) is proportional to N (3/2;
    • Keyword: Index sorting is proportional to N;
  • How to reduce overhead and speed up sorting(Important)
    • Use a more efficient algorithm
    • Shorten internal cycle
    • Check whether any comparison or exchange operations can be skipped
  • Sorting Stability
    If the keywords of the record to be sorted are not the same, the sorting result is unique. Otherwise, the sorting result is not unique.
    In the file to be sorted, if multiple records with the same keywords exist, the relative sequence of these records with the same keywords remains unchanged after sorting, and the sorting method is stable; if the relative order between records with the same keywords changes, this sorting method is not stable.
    Note:
    The ordering algorithm is stable for all input instances. That is, in all possible input instances, the Sorting Algorithm is unstable if one instance does not meet the stability requirements.
Basic Sorting Algorithm Type 1. Select sorting

Select the smallest element in the array, exchange it with the first element in the array, find the second small element, and exchange it with the second element in the array... Until the entire array is sorted. This is achieved by constantly selecting the smallest element in the remaining array.

2. Insert sorting and Hill sorting

By constructing an ordered sequence, unsorted data is scanned from the back to the forward in the sorted sequence to find the corresponding position for insertion. Therefore, in the process of scanning from the back to the forward, you need to repeatedly shift the sorted elements backward to provide the insert space for the new elements.

3. Bubble Sorting

Traverse the file. If the size of the two adjacent elements is not in the correct order, the two will be exchanged and repeat until the sorting is completed.

4. Index and pointer sorting, linked list sorting, and keyword sorting

Sorting by indexes, pointers, and linked lists: Indirect sorting with high flexibility. raw data and keyword information will not be changed.

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.