What sort algorithm provides the best worst-case performance?

后端 未结 16 2088
[愿得一人]
[愿得一人] 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:04

    The lowest upper bound on Turing machines is achieved by merge sort, that is O(n log n). Though quick sort might be better on some datasets.

    You can't go lower than O(n log n) unless you're using special hardware (e.g. hardware supported bead sort, other non-comparison sorts).

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

    make sure you have seen this:

    visualizing sort algorithms - it helped me decide what sort alg to use.

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

    It depends on the size, according to the Big O notation O(n).

    Here is a list of sorting algorithms BEST AND WORST CASE for you to compare. My preference is the 2 way MergeSort

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

    It all depends on the data you're trying to sort. Different algorithms have different speeds for different data. an O(n) algorithm may be slower than an O(n^2) algorithm, depending on what kind of data you're working with.

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

    If you have a sufficiently huge data set, you're probably looking at sorting individual bins of data, then using merge-sort to merge those bins. But at this point, we're talking data sets huge enough to be VASTLY larger than main memory.

    I guess the most correct answer would be "it depends".

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

    If you are using binary comparisons, the best possible sort algorithm takes O(N log N) comparisons to complete. If you're looking for something with good worst case performance, I'd look at MergeSort and HeapSort since they are O(N log N) algorithms in all cases.

    HeapSort is nice if all your data fits in memory, while MergeSort allows you to do on-disk sorts better (but takes more space overall).

    There are other less-well-known algorithms mentioned on the Wikipedia sorting algorithm page that all have O(n log n) worst case performance. (based on comment from mmyers)

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