排序算法的时间复杂度

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(n\log n) O(n) -O(n) extra space.
Heap sort O(n\log n) O(n) - in place,O(1) extra space.
Quicksort O(n^{2}) -O(n\log n) expected, andwith high probability. O(1) inplace.
Introsort O(n\log n) O(n) -O(\log n) extra space.
Counting sort O(k+n) O(k)
Timsort O(n) Best caseO(n\log n) Worst Case O(n)

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


posted on 2016-04-23 21:49  海岛Blog  阅读(102)  评论(0编辑  收藏  举报

导航