View Single Post
Old 12-03-2005, 07:42 PM   #5
Pangloth
Newbie

 
Join Date: Mar 2005
Location: ,
Posts: 10
Send a message via MSN to Pangloth
Default

Kon-Tiki, the example Quicksort source code you link to uses the leftmost element as the pivot, which could lead to disastrous results.

Imagine feeding sorted input to the algorithm. Then, because of the partitioning strategy, all elements will end up in the same half of the array. Worse, this happens consistently through the recursion, so the algorithm will take quadratic time to do nothing at all! Furthermore, input with largely sorted parts can be quite frequent in real life. This implementation is not recommended.

Median-of-three partitioning should be used instead.

That's why not having some understanding of what's going on can actually harm you.
Pangloth is offline                         Send a private message to Pangloth
Reply With Quote