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
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:
- Why do humans often sneeze twice?Best solution by Yahoo! Answers
- Why are ID's suddenly showing on my messenger instead of real names?Best solution by answers.yahoo.com
- Why do I have Yahoo Singapore instead of Yahoo United States?Best solution by Yahoo! Answers
- Why was the top level domain .co.uk used instead of .uk?Best solution by Yahoo! Answers
- Why do I often have blue feet?Best solution by healthtap.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.