跳到主要内容

排序

目的

将乱序的列表根据大小规则(1<21<2Monday<TuesdayMonday<Tuesday)进行排序

性能对比

算法时间复杂度(平均)时间复杂度(最坏)时间复杂度(最好)空间复杂度稳定性复杂性
直接插入排序O(n2)O(n^{2})O(n2)O(n^{2})O(n)O(n)O(1)O(1)稳定简单
希尔排序O(nlog2n)O(n\log_{2}{n})O(n2)O(n^{2})O(n1.3)O(n^{1.3})O(1)O(1)不稳定较复杂
直接选择排序O(n2)O(n^{2})O(n2)O(n^{2})O(n2)O(n^{2})O(1)O(1)不稳定简单
堆排序O(nlog2n)O(n\log_{2}{n})O(nlog2n)O(n\log_{2}{n})O(nlog2n)O(n\log_{2}{n})O(1)O(1)不稳定较复杂
冒泡排序O(n2)O(n^{2})O(n2)O(n^{2})O(n)O(n)O(1)O(1)稳定简单
快速排序O(nlog2n)O(n\log_{2}{n})O(n2)O(n^{2})O(nlog2n)O(n\log_{2}{n})O(nlog2n)O(n\log_{2}{n})不稳定较复杂
归并排序O(nlog2n)O(n\log_{2}{n})O(nlog2n)O(n\log_{2}{n})O(nlog2n)O(n\log_{2}{n})O(n)O(n)稳定较复杂
基数排序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)稳定较复杂