Sorting algorithm (ix)--Summary of eight large sorting algorithms

Source: Internet
Author: User

The stability and complexity of the eight ranking algorithms are summarized as follows:



Criteria for selecting sorting algorithms

Each sorting algorithm has its advantages and disadvantages. Therefore, when practical, it is necessary to choose according to different circumstances, or even combine various methods to use.

There are many factors that influence sequencing, and algorithms with low average time complexity are not necessarily optimal. Conversely, sometimes an algorithm with a high average time complexity may be better suited to some particular situation. At the same time, the selection algorithm should also consider its readability, in order to facilitate the maintenance of software. In general, there are four things to consider:

1. The size of the number of records to be sorted n;

2. The size of the data volume of the record itself, that is, the size of other information except the keywords in the record;

3. The structure and distribution of the keywords;

4. Requirements for sorting stability.

Set the number of elements to be sorted n.

1) when n is larger, it should be sorted by the time complexity O (nlog2n): Quick sort, heap sort, or merge sort order.

Quick sort: is currently considered the best method based on the comparison of internal sorting, when the keywords to be sorted are randomly distributed, the average time of the fast sorting is shortest;

Heap sort: If memory space permits and requires stability,

Merge sort: It has a certain number of data movement, so we may have a combination of the insertion sort, first get a certain length of sequence, and then merge, the efficiency will be improved.

2) When n is large, memory space allows, and requires stability, recommended merge sort

3) When n is small, it can be directly inserted or directly selected for sorting.

Direct Insert Sort: When the elements are distributed in an orderly manner, inserting the sort directly will significantly reduce the number of comparisons and moves recorded.

Direct selection Sort: element distribution is ordered, if stability is not required, select Direct Select sort

5) generally do not use or not directly use the traditional bubble sort.

6) Base Sorting

It is a stable sorting algorithm, but it has some limitations:

1, keywords can be decomposed.

2, record the number of key bits less, if dense better

3, if it is a number, it is best to be unsigned, otherwise it will increase the corresponding mapping complexity, you can first of its positive and negative sorting.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Sorting algorithm (ix)--Summary of eight large 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.