当使用非比较过比较排序排序

由网友(终会忘记℡)分享简介:在课堂上我们了解到,为了避免下限欧米茄(nlogn)所有基于比较各种各样的一堆新的非比较排序。但是,有一点我不清楚是赞成的和反对的何时使用排序算法的这家人。In class we learned about a bunch of new non-comparison sorts for the sake of avo...

在课堂上我们了解到,为了避免下限欧米茄(nlogn)所有基于比较各种各样的一堆新的非比较排序。但是,有一点我不清楚是赞成的和反对的何时使用排序算法的这家人。

In class we learned about a bunch of new non-comparison sorts for the sake of avoiding the lower bound of omega(nlogn) for all comparison based sorts. But what was a bit unclear to me was the pro's and con's to when to use which family of sorting algorithms.

不能任何数据集进行调整,使非比较排序算法(基数,斗,键索引)可以用吗?如果是这样,有什么比较各种各样的地步,甚至现有的?

Can't any data set be tweaked so that non-comparison sorting algorithms (radix, bucket, key-indexed) can be used? If so, what's the point of comparison sorts even existing?

对不起,这是这样一个基本的问题,但我真的找不到任何东西在网上。

Sorry for this being such a rudimentary question, but I really can't find anything online.

推荐答案

不是每个组项目可以调整使用非比较排序以一种有效的方式。例如,分类任意precision数字将需要运行循环桶内排序很多次,查杀性能。

Not every set of items can be tweaked to be used in non-comparison sorts in an efficient way. For example, sorting arbitrary precision numbers would require running the loop inside the bucket sort many times, killing the performance.

与基数各种世界的问题是,他们必须检查每个项目的每个元素进行排序。基于比较的排序,在另一方面,可以跳过的子元素(数字,字符等)。例如一相当数量,当比较功能检查两个字符串,它停止在该第一差值,跳过两者的尾部字符串。桶排序,而另一方面,必须检查所有字符每个字符串中的 * 。

The problem with radix sorts of the world is that they must examine every element of every item being sorted. Comparison-based sorts, on the other hand, can skip a fair number of sub-elements (digits, characters, etc.) For example, when a comparison function checks two strings, it stops at the first difference, skipping the tails of both strings. Bucket sort, on the other hand, must examine all characters in every string*.

在一般情况下,追逐最好的渐进复杂性并不总是一个不错的策略:N,其中使用显著更复杂的算法的价值回报往往过高,使更复杂的算法实用。例如,快速排序有非常坏的愈的时间复杂度,但平均被它打败了其他大多数算法手了,由于其非常低的开销,使得它在大多数实际情况是不错的选择。 * 在实践中桶的实现排序避免需要通过切换到看所有子元素(数字,字符等)的比较为基础的排序一旦物品在一个桶中下降到低于某一阈值。这种混合方法击败既是一个简单的比较为基础的分类和一个普通的桶排序。

In general, chasing the best asymptotic complexity is not always a good strategy: the value of N where using a significantly more complex algorithm pays off is often too high to make the more complex algorithms practical. For example, quicksort has very bad worse time complexity, yet on average it beats most other algorithms hands down due to its very low overhead, making it a good choice in most practical situations. * In practice implementations of bucket sort avoid the need to look at all sub-elements (digits, characters, etc.) by switching to a comparison-based sort as soon as the number of items in a bucket drops below a certain threshold. This hybrid approach beats both a plain comparison-based sort and a plain bucket sort.

阅读全文

相关推荐

最新文章