Question

Quicksort outperforms Heapsort in practice. Mergesort is the only stable one of the 3 (in plain vanilla implementations). So it's either quicksort or mergesort that'd get used depending on the situation at hand (in-place in memory or external sorting etc.,)

So is there ever a case where the heap data structure is indeed used for sorting? No matter how much I 'Google' or try to come up with applications, almost always one chooses merge/quick-sort over heapsort. I've never encountered a case where heap sort is actually used in my professional life either. What would actually be a good use-case for heapsort in practice (if at all), out of curiosity?

Était-ce utile?

La solution

Some benefits off the top of my head (will amend this list after I do some more research:

  • Almost-sorted sets benefit from being sorted by heapsort.
  • Space-conscious environments often prefer the O(1) space complexity of heapsort. Think embedded systems.
  • Huge data sets benefit from the guaranteed running time of O(nlog n) as opposed to the probable better running time of quicksort. Think medical, space, life-support, etc.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top