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.
|