![]() ![]() However, I have yet to see a proper justification of this, with precise calculations instead of intuitive ideas only. Update 1: a canonical answer is saying that the constants involved in the $O(n\log n)$ of the average case are smaller than the constants involved in other $O(n\log n)$ algorithms. Why, then, does quicksort outperform other sorting algorithms in practice? Does it have to do with the structure of real-world data? Does it have to do with the way memory works in computers? I know that some memories are way faster than others, but I don't know if that's the real reason for this counter-intuitive performance (when compared to theoretical estimates). ![]() Therefore (and even though this is not a real argument), this gives the idea that quicksort might not be really good because it is a recursive algorithm. At the same time, other sorting algorithms are studied which are $O(n \log n)$ in the worst case (like mergesort and heapsort), and even linear time in the best case (like bubblesort) but with some additional needs of memory.Īfter a quick glance at some more running times it is natural to say that quicksort should not be as efficient as others.Īlso, consider that students learn in basic programming courses that recursion is not really good in general because it could use too much memory, etc. In a standard algorithms course we are taught that quicksort is $O(n \log n)$ on average and $O(n^2)$ in the worst case. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |