What sort algorithm provides the best worst-case performance?

后端 未结 16 2087
[愿得一人]
[愿得一人] 2020-12-15 14:44

What is the fastest known sort algorithm for absolute worst case? I don\'t care about best case and am assuming a gigantic data set if that even matters.

相关标签:
16条回答
  • 2020-12-15 15:17

    Assuming randomly sorted data, quicksort.

    O(nlog n) mean case, O(n^2) in the worst case, but that requires highly non-random data.

    You might want to describe your data set characteristics.

    0 讨论(0)
  • 2020-12-15 15:18

    Depends on data. For example for integers (or anything that can be expressed as integer) the fastest is radix sort which for fixed length values has worst case complexity of O(n). Best general comparison sort algorithms have complexity of O(n log n).

    0 讨论(0)
  • 2020-12-15 15:18

    On the importance of specifying your problem: radix sort might be the fastest, but it's only usable when your data has fixed-length keys that can be broken down into independent small pieces. That limits its usefulness in the general case, and explains why more people haven't heard of it.

    http://en.wikipedia.org/wiki/Radix_sort

    P.S. This is an O(k*n) algorithm, where k is the size of the key.

    0 讨论(0)
  • 2020-12-15 15:19

    It largely is related to the size of your dataset and whether or not the set is already ordered (or what order it is currently in).

    Entire books are written on search/sort algorithms. You aren't going to find an "absolute fastest" assuming a worst case scenario because different sorts have different worst-case situations.

    0 讨论(0)
提交回复
热议问题