It was already explained...
Posted Jan 22, 2012 0:54 UTC (Sun) by khim
In reply to: Heapsort is useless in real world...
Parent article: Denial of service via hash collisions
Except that, is there a pathological case for heap sort?
Sometimes it's good idea to actually look up further upthread.
It's actually a very well behaved sort.
No, it's absolutely not. It's quite good WRT to comparisons and swaps, but it's absolute disaster WRT to memory access. If you data fit in L1 cache (16K-32K) it works just fine, if you hit L2 and/or L3 cache you start doing worse then merge sort or quick sort, but difference is tolerable (typically less then 2x). The real disaster happens once you hit main memory: to read one number from random address in memory you need about 250-300 ticks (and this is what happens with heapsort because prefetch can not cope with it's memory access patterns), while sustained sequential access gives you next 32bit number in 2-3 ticks. Since some part of heap will be in cache even for large arrays heapsort does not suddenly become 50-100 times slower then mergesort when you pass L3 border, to get to this level of difference you need hundreds of gigabytes of data.
to post comments)