微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

有效排序

我有一个数组的数组,几乎是但不是很好的排序,有几个值被替换(比如,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.

原文地址:https://www.jb51.cc/c/112522.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐