Bluepixel wrote:
Why doesn't perl use heapsort?
Because there are no real advantages to heap sort for general sorting,
except for the ability of doing in-situ sorting, but that's not relevant
with Perl's sort routine. The particular implementation of mergesort Perl
is using has a few advantages: it's stable and it performs very well
with sorted, or nearly sorted data. It also has a tight upperbound,
it's worst-case behaviour is O (N log N). And while the quicksort
implementation isn't stable (it could be made stable at some costs) and
runs in quadratic time with some inputs, it runs fast on random data -
for two reasons: the algorithm used, and it's very memory
cache friendly (most computers nowadays have a memory cache).
Neither mergesort and heapsort are cache friendly - they go all over
the place.
Abigail
| [reply] |