Sort--Summary

Source: Internet
Author: User

Summarize:
Categories with large sorting can be divided into two types: inner and outer sort. In the sort process, all records are stored in memory, which is called an inner sort, and is called an out-of-order if you need to use external memory during sorting. The sort that follows is an inner sort.
Within a sort can be divided into the following categories:
(1), insert Sort: Direct insert sort, dichotomy insert sort, hill sort.

(2), select Sort: Simple select sort, heap sort.

(3), Exchange sort: bubble sort, quick sort.

(4), merge sort

(5), base sort

First, Stability:

Stabilize: Bubble sort, insert sort, merge sort, and Cardinal sort

Instability: Select sort, quick sort, hill sort, heap sort

Second, the average time complexity

O (n^2): Direct insert Sort, simple select sort, bubble sort.

In the case of small data size (9W), the direct insertion of the sort, simple selection of sort almost. The bubbling sorting algorithm has the highest time cost when the data is large. The Performance O (n^2) algorithm is basically a comparison of adjacent elements, which are basically stable.

O (NLOGN): Quick Sort, merge sort, hill sort, heap sort.

Among them, the fastest row is the best, followed by the merger and Hill, heap sorting in the data is very large when the effect is obvious.

Three, the choice of sorting algorithm

1. Small Data size

(1) In the case of the basic sequence of the sequence to be sorted, you can choose the direct insertion sort;

(2) The stability is not required to use simple selection of sorting, stability requirements should be inserted or bubbling

2. Data size is not very large

(1) Completely can use memory space, the sequence is disorderly, there is no requirement for stability, fast sorting, at this time to pay the log (N) extra space.

(2) The sequence itself may be orderly, to the stability of the requirements, space permitting, it is appropriate to use the merge sort

3. Data size is large

(1) For the stability of the request, you can consider the merger sort.

(2) Not required for stability, should be sorted by heap

4. Sequence initial basic order (positive order), preferably with direct insertion, bubbling

Sort--Summary

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.