Why do we use quicksort instead of heapsort?

Why is quicksort often used instead of heapsort?

  • Why is heap sort not accepted much even though it runs in O(nlogn) in worst case with O(1) constant space?

  • Answer:

    You can have a look at this paper https://www.cs.auckland.ac.nz/~jmor159/PLDS210/qsort3.html It actually does a comparison of Quick sort with heap sort for a given data. Except for the occasional O(n^2) worst case you can see the quicks sort performs better. Found this in stackexchange: This is done in Don Knuth's book series “The Art of Computer Programming” for an artificial “typical” computer invented by the author. In volume 3 you find exact average case results for many sorting algorithms, e.g. Quicksort: 11.667(n+1)ln(n)−1.74n−18.74 Mergesort: 12.5nln(n) Heapsort:  16nln(n)+0.01n Insertionsort: 2.25n2+7.75n−3ln(n) Looking at the constants you can say that Quicksort is fastest. But, it is only proved on Knuth's artificial machine.

Abhiroop Sarkar at Quora Visit the source

Was this solution helpful to you?

Other answers

Heap sort is much more complicated and has a higher constant factor than median of 3 quick sort on expectation, and hence runs a bit slower. It is also wrong to say heap sort isn't used. The standard c++ implementation first sorts with quick sort and if the partitions haven't reduced as much as expected then calls heap sort. This sort function is then used in Linux, and many other applications. http://en.m.wikipedia.org/wiki/Sort_(C%2B%2B)

Abhimanyu Mongandh Ambalath

This answer might be helpful:

Pawan Bhadauria

Quicksort maintains the order of data and hence it is stable. Heap sort is unstable as it does not maintain the order and in real time sorting that is unacceptable.

Mohit Golchha

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.