So, as we see, Heap Sort has better worst case complexity than every other algorithm mentioned, both in time and space. So what is the algorithm that everyone uses to sort a generic sequence?
Sigiloso
Well, if probably mean the standard library implementations of functions like `sort`, then it depends on languages and compilers. Popular Java implementations use double-pivotic Quick Sort. CPython uses Tim Sort, which is a variation of Merge Sort that tries to find sorted subsequences. As far as I imagine, the implementation of C++ std::sort may depend on the length of the sequence. For small arrays, it may use merge sort or even some quadratic algo. For large arrays it probably uses Quick Sort. So, why not Heap Sort? Quick Sort has O(n^2) worst-case time (if we are unlucky or our pivot-selection is compromised), and Merge Sort needs O(n) space. My best bet is cache-obliviousness. For every element popped out from array-based heap, we have to make O(log(n)) accesses to distant places in memory. If the array is much larger than cache line, this can lead to cache-misses and overall greater wall time. Quick Sort, on the other hand, processes memory relatively consequtively, reducing the number of cache misses.