Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is heapsort ever used in practice? [closed]

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?

like image 209
PhD Avatar asked Dec 30 '12 01:12

PhD


1 Answers

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.
like image 78
David Titarenco Avatar answered Sep 28 '22 12:09

David Titarenco