Quote:
Originally Posted by mina86
Really? No one mentioned that QuickSort is O(n^2) yet?[1] In the worst case it degenerates to select sort. That's why I much prefer Heap Sort (if I don't care if sorting is stable, but even if I do, I would probably just number the elements and sort by double key).
|
That's why I said, "minimum running time".
It is true that in the worst case, quick sort is just select sort run with recursion. It might even have an exponential running time because of the recursion (like with fibonacci numbers) but I can't say for certain.
Of course, this is most unlikely if you choose a random pivot. You should also avoid advancing your pointers if the element's key is equal to the pivot since that can also lead to lop-sided partitioning. (It turns out that it is better to simply exchange elements who's keys are equal to the pivot than to test for the equality).
Jonathon Shewchuck gives a very good lecture on quicksort in this
YOU TUBE.
I am also impressed with heapsort. It might not be as fast as quicksort but it still runs in NlogN time and with its in-array sorting and lack of recursion, it makes an ideal candidate in situations where memory is tight.
The irony is that these fancy sorting routines are often at their worst when dealing with already sorted data.