排序算法的时间复杂度

Sorting Algorithms and Complexities

  • n is the number of elements
  • k is the number of distinct objects
Algorithm Time Complexity Space Complexity
Bubble sort O(n^{2}) O(n) - in place,O(1) extra space.
Insertion sort O(n^{2}) O(n) - in place,O(1) extra space.
Selection sort O(n^{2}) O(n) - in place,O(1) extra space.
Merge sort O(nlog n) O(n) -O(n) extra space.
Heap sort O(nlog n) O(n) - in place,O(1) extra space.
Quicksort O(n^{2}) -O(nlog n) expected, andwith high probability. O(1) inplace.
Introsort O(nlog n) O(n) -O(log n) extra space.
Counting sort O(k+n) O(k)
Timsort O(n) Best caseO(nlog n) Worst Case O(n)

文章出处:http://www.algorithmist.com/index.php/Sorting


原文地址:https://www.cnblogs.com/tigerisland/p/7564942.html