Sorting Overview of Sorting Algorithm Series 0

The sorting algorithm has evolved over a long period of time, resulting in many different methods. For beginners, it is very important to organize them so that they can easily understand and remember. Each algorithm has its specific use occasions, and it is difficult to be universal. Therefore, it is necessary to summarize all common sorting algorithms.

The sorts with large sorting can be divided into two types: inner sorting and outer sorting. In the sorting process, all records are stored in memory, which is called internal sorting. If external storage is used in the sorting process, it is called external sorting. The following sorts are all sorts within.

The internal sorting can be divided into the following categories:

  (1) Insertion sorting: direct insertion sorting, dichotomy insertion sorting, Hill sorting.

  (2), selection sorting: direct selection sorting, heap sorting.

  (3) Exchange sorting: bubble sorting and quick sorting.

  (4), merge sort

  (5), cardinality sorting

Tabular version:

Sorting method Time complexity (average) Time complexity (worst) Time complexity (best) Space complexity stability Complexity
Direct insertion sort O ( n 2 ) O (n2) O ( n 2 ) O (n2) O ( n ) O (n) O ( 1 ) O (1) stable simple
Hill Sort O(nlog2n)O(nlog2n) O ( n 2 ) O (n2) O ( n ) O (n) O ( 1 ) O (1) Unstable More complicated
Direct selection sort O ( n 2 ) O (n2) O ( n 2 ) O (n2) O ( n 2 ) O (n2) O ( 1 ) O (1) Unstable simple
Heap sort O(nlog2n)O(nlog2n) O(nlog2n)O(nlog2n) O(nlog2n)O(nlog2n) O ( 1 ) O (1) Unstable More complicated
Bubble Sort O ( n 2 ) O (n2) O ( n 2 ) O (n2) O ( n ) O (n) O ( 1 ) O (1) stable simple
Quick sort O(nlog2n)O(nlog2n) O ( n 2 ) O (n2) O(nlog2n)O(nlog2n) O(nlog2n)O(nlog2n) Unstable More complicated
Merge sort O(nlog2n)O(nlog2n) O(nlog2n)O(nlog2n) O(nlog2n)O(nlog2n) O ( n ) O (n) stable More complicated
Cardinality sorting O(d(n+r))O(d(n+r)) O(d(n+r))O(d(n+r)) O(d(n+r))O(d(n+r)) O(n+r)O(n+r) stable More complicated

 

 Picture version:

 

Guess you like

Origin www.cnblogs.com/wangxiucai/p/12679667.html