Generic and practical sorting algorithm faster than O(n log n)?

前端 未结 4 1081
情深已故
情深已故 2021-02-13 11:21

Is there any practical algorithm for generic elements (unlike counting sort or bucket sort) that runs faster than O(n log n)?

4条回答
  •  孤独总比滥情好
    2021-02-13 11:55

    For generic elements that you can only compare and not access the internals of, it is impossible to have a sorting algorithm faster than Theta(n log n). That is because there are n! (n factorial) possible orders of the elements, and you need Theta(n log n) comparisons to distinguish all of them.

提交回复
热议问题