堆排序还是快速排序更好的? [英] Heap sort or quick sort better one?

查看:152
本文介绍了堆排序还是快速排序更好的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我给写轮的一家公司。 我有一个疑问,在一个问题,谁能帮助我?

I gave a written round of a company. I have a doubt in a question can anyone help me?

这是以下中最快的排序算法?
  一个 - 冒泡排序
  b - 希尔排序
  Ç - 堆排序
  ð - 快速排序

which is the fastest sorting algorithm among the following?
a - bubble sort
b - shell sort
c - heap sort
d - quick sort

我很困惑的B / W快速排序和堆排序都有O(nlogn)的时间复杂度。

I'm confused b/w quick sort and heap sort both have a time complexity of O(nlogn).

推荐答案

有没有最快的排序算法。

There's no "fastest" sorting algorithm.

的算法的理论性能总是取决于输入数据。在各自的最坏的情况下的,堆排序比快速排序更快。在一般情况下,快速排序更快。这可能是可以编造一个量身定制的最好的情况下的每个算法,使其胜过所有其他人。

Theoretical performance of an algorithm always depends on the input data. In their respective worst cases, Heap sort is faster than Quick sort. In average case, Quick sort is faster. It is probably possible to concoct a custom-tailored best case for each algorithm to make it outperform all the others.

这其实是这样的混合型的算法作为的 Introsort 的存在理由:Introsort开始与快速排序,并切换到堆排序,如果它看到了快速排序的努力奋斗着这个特定的输入。

That is actually the reason such "hybrid" algorithms as Introsort exist: Introsort begins with Quick sort and switches to Heap sort if it sees that Quick sort is struggling with this specific input.

在任何的算法是,现实生活中的表现上面可以显著的影响以及它如何运作在一个特定的硬件平台。理论上快算法惨败输给一个原始的慢之一,如果后者是更好的同步与硬件的属性。

On top of that the real-life performance of any algorithm can be significantly affected by how well it works on a specific hardware platform. A theoretically "fast" algorithm can lose miserably to a primitive and "slow" one, if the latter is in better "sync" with the properties of the hardware.

这篇关于堆排序还是快速排序更好的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆