Comparison of Internal Sorting Algorithms

Comparison of Internal Sorting Algorithms

Comparison of Internal Sorting Algorithms

Algorithm type best time complexity average time complexity worst time complexity space complexity Is it stable Whether the number of sorting times is related to the initial state of the sequence Whether the number of comparisons is related to the initial state of the sequence
direct insertion sort O ( n ) O(n)O ( n ) O ( n 2 ) O( n^{2} )O ( n2) O ( n 2 ) O( n^{2} )O ( n2) O(1) O(1)O(1) yes irrelevant related
Bubble Sort O ( n ) O(n)O ( n ) O ( n 2 ) O( n^{2} )O ( n2) O ( n 2 ) O( n^{2} )O ( n2) O(1) O(1)O(1) yes related related
simple selection sort O ( n 2 ) O( n^{2} )O ( n2) O ( n 2 ) O( n^{2} )O ( n2) O(n^2) O(1) O(1)O(1) no irrelevant irrelevant
Hill sort null null null O(1) O(1)O(1) no irrelevant related
quick sort O ( nlog 2n ) O(nlog_2n)O ( n l o g2n) O ( nlog 2n ) O(nlog_2n)O ( n l o g2n) O ( n 2 ) O( n^{2} )O ( n2) O ( nlog 2n ) O(nlog_2n)O ( n l o g2n) no related related
heap sort O ( nlog 2n ) O(nlog_2n)O ( n l o g2n) O ( nlog 2n ) O(nlog_2n)O ( n l o g2n) O ( nlog 2n ) O(nlog_2n)O ( n l o g2n) O(1) O(1)O(1) no irrelevant related
2-way merge sort O ( nlog 2n ) O(nlog_2n)O ( n l o g2n) O ( nlog 2n ) O(nlog_2n)O ( n l o g2n) O ( nlog 2n ) O(nlog_2n)O ( n l o g2n) O ( n ) O(n)O ( n ) yes irrelevant irrelevant
radix sort 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 ( d ( n + r ) ) O(d(n+r))O(d(n+r)) O ( r ) O ( r )O ( r ) yes irrelevant irrelevant

Since the time complexity of Hill sorting is a mathematical problem that has not yet been solved, this table is not indicated yet.

Guess you like

Origin blog.csdn.net/dwh19992018/article/details/127552675