c – 对已经对某些数字进行排序的数组进行部分排序

我必须按降序对数组进行部分排序,其中某些数字可能已经排序.

他们的任何功能是否可以有效地执行它或任何有效的算法.

最佳答案
Timsort专为该案例而设计.

Timsort is a hybrid sorting algorithm, derived from merge sort and
insertion sort, designed to perform well on many kinds of real-world
data. It was invented by Tim Peters in 2002 for use in the Python
programming language. The algorithm finds subsets of the data that are
already ordered, and uses the subsets to sort the data more
efficiently.

另一个替代方案是Smoothsort,也是为了利用部分排序的数据而设计的.

It is a variation of heapsort developed by Edsger Dijkstra in 1981.
Like heapsort, smoothsort’s upper bound is O(n log n). The
advantage of smoothsort is that it comes closer to O(n) time if the
input is already sorted to some degree, whereas heapsort averages
O(n log n) regardless of the initial sorted state.

转载注明原文:c – 对已经对某些数字进行排序的数组进行部分排序 - 代码日志