Exercise 9.3.3
Show how quicksort can be made to run in
O(nlgn) time in the worst case, assuming that all elements are distinct.
If we rewrite PARTITION to use the same approach as SELECT, it will perform in
As of exercise 4.4.9, we know that this is
And that's how we can prevent quicksort from getting quadratic in the worst case, although this approach probably has a constant that is too large for practical purposes.
Another approach would be to find the median in linear time (with SELECT) and partition around it. That will always give an even split.
Read full article from Exercise 9.3.3
No comments:
Post a Comment