选择与合并排序问题
假设我们的交换(a,b)(非常昂贵)的函数的实现效率低下,并且我们可以选择四种排序算法可供选择,即:
- 合并
- 选择插入插入插入
- 插入插入堆
- 堆积,
这是以下之一四个会表现最好?
现在,根据我的说法,因为掉期是一项昂贵的操作,我们需要最大程度地减少掉期数量。因此,从技术上讲,答案应合并排序,因为它在其一般实施中没有执行交换。但是答案键表明它必须是选择选择?我不明白为什么,请帮忙。
选择排序首先找到正确的索引,然后掉期经济的互换,但合并排序的表现还不错?
Suppose we have inefficient implementation of swap(a,b)(very costly) function and we are given the choice of four sorting algorithms to choose from, namely:
- merge-sort
- selection-sort
- insertion-sort
- heap-sort
Which one of the following four will perform the best ?
Now according to me as the swap is a costly operation we need to minimise the number of swaps. so technically the answer should be merge sort as it performs no swapping in its general implementation. But the answer-key suggests that it must be selection-sort instead ? I fail to understand why, please help.
Selection sort first finds the correct index and then swaps which is economical but doesn't merge sort perform better still ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论