有效排序

我有一个数组的数组,几乎是但不是很好的排序,有几个值被替换(比如,100000中的50).如何最有效地排序?

解决方法

在数组几乎排序的假设下,您可以使用以下之一:

Smoothsort

Wiki甚至有一个java实现就可以了.因为你不能比O(n)快得多(因为为了甚至找出数组是否排序需要很多时间)smoothsort是一个不错的选择.更多细节here.

The advantage of smoothsort is that it
comes closer to O(n) time if the input
is already sorted to some degree

Coctail sort

The complexity of cocktail sort in big
O notation is O(n2) for both the worst
case and the average case,but it
becomes closer to O(n) if the list is
mostly ordered before applying the
sorting algorithm,

Timsort

Java的数组实际上是在java 7中使用timsort来排序对象(sort()).时钟说明here.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...