gpt4 book ai didi

arrays - 为什么快速排序平均比其他排序快?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:31:53 25 4
gpt4 key购买 nike

正如我们所知,快速排序的平均性能为 O(n*log(n)),但合并和堆排序的平均性能也为 O(n*log(n))。所以问题是为什么快速排序平均速度更快。

最佳答案

Wikipedia suggests :

Typically, quicksort is significantly faster in practice than other O(nlogn) algorithms, because its inner loop can be efficiently implemented on most architectures, and in most real-world data, it is possible to make design choices that minimize the probability of requiring quadratic time. Additionally, quicksort tends to make excellent usage of the memory hierarchy, taking perfect advantage of virtual memory and available caches. Although quicksort is not an in-place sort and uses auxiliary memory, it is very well suited to modern computer architectures.

另请查看 comparison with other sorting algorithms在同一页上。

另见 Why is quicksort better than other sorting algorithms in practice?在 CS 网站上。

关于arrays - 为什么快速排序平均比其他排序快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4289024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com