Skip to content
Prev 578 / 63421 Next

R-alpha: Sorting Efficiency -- thoughts.. : if(!is.sorted(x)) x <- sort(x)

Martin Maechler <maechler@stat.math.ethz.ch> writes:
Actually, if it's a Shell sort, it's O(n^1.5) worst case and O(n^1.27)
average. For O(n log n) average you need quicksort or heapsort. The
former has the draw back of O(n^2) worst case, but heapsort has quite
a good reputation and is unconditionally n log n (that info comes from
Numerical Recipes, which was the best could dig out at the moment).
Maybe we should switch?
Yes.. Of course the case is often that you *know* that things are
sorted (because you just did it yourself), but modularity prevents you
from getting that information to the spot where it is needed.