Skip to content

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

1 message · Luke Tierney

#
Peter Dalgaard BSA wrote:
Merge sort is also an option. It is O(n log(n)) worst case but with a
better constant than heapsort, as I recall, and a bit easier to
implement.  Its drawback in general is O(n) additional space needed,
which is prohibitive if you are sorting in place. But since R copies
anyway, that isn't an issue. (Don't name any internal routines
mergesort though -- there are a number of systems that include one in
their libraries and cause name conflicts).

luke