Comparison of typical sorting algorithms

Source: Internet
Author: User

Sorting is sorted into inner and outer sort, depending on whether the band sort data is all put into memory.

The following is based on my experience of reading, the main analysis of the performance of the sorting.


Sort within: Insert sort (direct insert sort, hill Sort), select sort (Simple select sort, heap sort), swap sort (bubble sort, quick sort), merge sort.

More of them are insert sort, merge sort, quick sort.


Comparison of sorting algorithms: Performance comparisons can be analyzed in the following 5 ways: Time complexity (average, best, worst case), spatial complexity (auxiliary space), stability.



On average, three improved algorithms are better than hill sort, and are much better than three simple algorithms.

In the best case scenario, bubbling and direct insert sorting is better, meaning that four complex algorithms should not be used in cases where the sorted data is basically ordered.

Worst case perspective, heap Sorting and merge sorting are better.


The spatial complexity angle, the merge sort emphasizes to want to run fast, must give enough space; The fast sort also has the corresponding space complexity requirement; In contrast, the heap sorting space complexity position O (1), a small amount of demand, a lot of pay type. Therefore, when the algorithm execution environment is very concerned about memory usage, choosing heap sorting is a good choice, and merging sorting and quick sorting is not the best choice.


The stability angle, the merge sort is the champion. In the case of high algorithm stability, merge sort is the only choice.


The number of records to be sorted, the smaller the number of records, the more simple sorting should be selected. For example, when optimizing a quick sort, one aspect is that in cases where the number of records is less than a certain threshold, the insertion sort should be used.



The angle of the number of moves, simple selection of sorting advantage is very large.


Comparison of typical sorting algorithms

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.