排序算法的时间复杂度

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) - in place, extra space.
Insertion sort O(n) - in place, extra space.
Selection sort O(n) - in place, extra space.
Merge sort O(n\log n) O(n) - O(n) extra space.
Heap sort O(n\log n) O(n) - in place, extra space.
Quicksort - O(n\log n) expected, and with high probability. inplace.
Introsort O(n\log n) O(n) - O(\log n) extra space.
Counting sort O(k)
Timsort O(n) Best case O(n\log n) Worst Case O(n)

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


你可能感兴趣的:(复杂度,排序算法)