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
Related Q & A:
- Why to use Google in-app billing?Best solution by developer.android.com
- Why do we use Gross Domestic Product instead of Net Domestic Product?Best solution by Yahoo! Answers
- Why should use the search engine?Best solution by Yahoo! Answers
- Can i use calamansi instead of lemon?Best solution by Yahoo! Answers
- Why would you use symmetric encryption instead of asymmetric one?Best solution by Quora
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.