跳到主要内容

排序(Sorting)

10 大排序算法

名称最好时间复杂度最坏时间复杂度平均时间复杂度额外空间复杂度原地排序稳定性
冒泡排序(Bubble Sort)O(n)O(n2)O(n2)O(1)
选择排序(Selection Sort)O(n2)O(n2)O(n2)O(1)
插入排序(Insertion Sort)O(n)O(n2)O(n2)O(1)
归并排序(Merge Sort)O(nlogn)O(nlogn)O(nlogn)O(n)
快速排序(Quick Sort)O(nlogn)O(n2)O(nlogn)O(logn)
希尔排序(Shell Sort)O(n)O(n4/3) ~ O(n2)取决于步长序列O(1)
堆排序(Heap Sort)O(nlogn)O(nlogn)O(nlogn)O(1)
计数排序(Counting Sort)O(n + k)O(n + k)O(n + k)O(n + k)
基数排序(Radix Sort)O(d ∗ (n + k))O(d ∗ (n + k))O(d ∗ (n + k))O(n + k)
桶排序(Bucket Sort)O(n + k)O(n + k)O(n + k)O(n + m)