Sorting Algorithm - Summary

Sorting Algorithm - Summary

  1. Comparison of commonly used sorting algorithm
Sorting Algorithm The average time complexity The best time complexity The worst time complexity Space complexity stability
Bubble Sort O (N 2 ) O (n) O (N 2 ) O (1) stable
Selection Sort O (N 2 ) O (N 2 ) O (N 2 ) O (1) Unstable
Insertion Sort O (N 2 ) O (n) O (N 2 ) O (1) stable
Shell sort O(n log n) O(n log2 n) O(n log2 n) O (1) Unstable
Merge sort O(n log n) O(n log n) O(n log n) O (n) stable
Quick Sort O(n log n) O(n log n) O (N 2 ) O(log n) Unstable
Heapsort O(n log n) O(n log n) O(n log n) O (1) Unstable
Radix Sort O(n x k) O(n x k) O(n x k) O(n + k) stable
Bucket sort O(n + k) O(n + k) O (N 2 ) O(n + k) stable

Notes:
1. The stability and instability: for the same elements a and b, if a still after sorting in front of b, a and b is so stable, if changed the original sequence, it is unstable
2. inner and outer Sort Sort: the above table is sorted order. Sorting is within all of the sorting process is done in memory, external sorting data processing is too large to be processed by the disk
Complexity 3. Time: an algorithm execution time required to complete
4. Space Complexity: End Run an algorithm required for the program memory size
5.n refers to the size of the data, that is, how much would you like the data
6.k is the number of buckets, under normal circumstances is 10

Published 25 original articles · won praise 3 · Views 1576

Guess you like

Origin blog.csdn.net/Blackoutdragon/article/details/103979283