Why do we use quicksort instead of heapsort?

Why we use quicksort instead of heapsort?

  • In most cases we use quicksort instead of heapsort...Why is that? because i read somewhere that best case for both algo is O(n.log n) but the worst case for quicksort is O(n^2) and for heapsort is O(n log n). Here we notice that heapsort wolud have a better hand considering the worst case scenario. But we prefer quicksort instead please anyone explain this

  • Answer:

    It usually doesn't matter what algorithm you use. Write your program using whichever one is the easiest to implement (in C, for example, you might just use the qsort function which is provided by the standard library), then once your programs finished run it with a profiler and if you notice that your program spends most of its time in the sorting function, then try more complicated algorithms (like quicksort or heapsort) until the bottleneck is removed. There isn't much point in using a highly optimised sorting function if a simpler algorithm (like insertion sort) performs just as well.

D at Yahoo! Answers Visit the source

Was this solution helpful to you?

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.