Summary and comparison of comprehensive 8 seed sorting algorithms

Source: Internet
Author: User

1 High-speed sorting (QuickSort)

The high-speed sort is a place to sort, divide and conquer. Mass recursive algorithm. In essence, the merge sort place is the version number.

The following four steps for high-speed sequencing can be made by the.

(1) No more than 1 data. return directly.

(2) General selection of the leftmost value of the sequence as pivot data.

(3) Divide the sequence into 2 parts. Part is larger than pivot data, and the other part is smaller than pivot data.

(4) Use recursion to sort the series on both sides.

High-speed sequencing is faster than most sorting algorithms.

Although we are able to write algorithms that are faster than high-speed sequencing in some special cases, it is usually the case. Nothing is faster than it. High-speed sequencing is recursive, and it is not a good choice for machines with limited memory.

2 merge sort (mergesort)

The merge sort first decomposes the sequence to be sorted, from 1 to 2. 2 is divided into 4, then decomposed, and when decomposed into just 1 groups, it is possible to sort the groupings and then merge back into the original sequence in turn. This allows you to sort all the data. A merge sort is slightly faster than a heap, but requires more memory space than a heap sort. Because it requires an extra array.

3 heap sequencing (heapsort)

Heap sequencing is suitable for situations where data volumes are large (millions of data).

Heap ordering does not require a large number of recursive or multidimensional staging arrays.

This is appropriate for a sequence with a large amount of data. For example, more than millions of records. Because of the high-speed sorting, the merge sort uses the recursive design algorithm, when the data volume is very large. A stack overflow error may occur.

The heap sort will make all the data into a heap, the largest data at the top of the heap, and then exchange the heap top data and the last data of the sequence. Then rebuild the heap again. Exchange data, and in turn, you can sort all of the data.

4 Shell sort (shellsort)

Shell sorting is done by dividing the data into different groups. Sort each group first, and then insert the entire element one at a time. To reduce the number of times data is exchanged and moved. The average efficiency is O (NLOGN). The rationality of the grouping will have an important influence on the algorithm.

Nowadays, we use D.e.knuth's grouping method more.

The shell sort is 5 times times faster than the bubble sort, twice times faster than the insertion sort. Shell sorting is better than quicksort,mergesort. Heapsort is much slower. But it is relatively simple, it is suitable for the amount of data under 5000 and speed is not particularly important occasions. It is very good for repeated sequencing of smaller data volumes.

5 Insert Sort (insertsort)

Insert sort by inserting the values in the sequence into a sequence that is already sorted until the end of the sequence. Insert sort is an improvement to the bubbling sort. It's twice times faster than bubble sort. It is generally not necessary to use an insert sort when the data is greater than 1000, or to reorder more than 200 data items.

6 Bubble sort (bubblesort)

Bubble sort is the slowest sort algorithm.

It is the least efficient algorithm in practical application. It passes through the Bandi of each element in the array. So that the larger data sinks, the smaller data rises.

It is an O (n^2) algorithm.

7 Interchange Sort (exchangesort) and select Sort (selectsort)

Both of these sorting methods are sorting algorithms for the interchange method. Efficiency is O (n2). In the actual application is in the same position as bubble sort. They are only 0 basic stages of the development of sequencing algorithms. Less used in practice.

8 Cardinal Sort (Radixsort)

The Cardinal sort and the usual sorting algorithm do not go the same way.

It is a relatively novel algorithm, but it can only be used for the ordering of integers, assuming we want to apply the same method to the floating point number. We must understand the storage format of floating-point numbers. It's a hassle to map floating-point numbers to integers and then map them back in a special way. So. Its use is not much the same.

And. The most important thing is. This algorithm also needs more storage space.

9 Summary

The following is a general table. Summarizes the characteristics of all of our common sorting algorithms.

Sorting method

Average Time

Worst case scenario

Degree of stability

Extra Space

Note

Bubble

O (n2)

O (n2)

Stability

O (1)

N Hours better

Exchange

O (n2)

O (n2)

Not stable

O (1)

N Hours better

Choose

O (n2)

O (n2)

Not stable

O (1)

N Hours better

Insert

O (n2)

O (n2)

Stability

O (1)

Most are sorted better

Base

O (LOGRD)

O (LOGRD)

Stability

O (N)

D is the number of keyword (0-9).

R is Cardinal number (1000)

Shell

O (NLOGN)

O (ns) 1<s<2

Not stable

O (1)

S is the selected grouping

High speed

O (NLOGN)

O (n2)

Not stable

O (NLOGN)

Better when N is big

Merge

O (NLOGN)

O (NLOGN)

Stability

O (1)

Better when N is big

Heap

O (NLOGN)

O (NLOGN)

Not stable

O (1)

Better when N is big

Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Summary and comparison of comprehensive 8 seed 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.