Unformatted text preview: appens if we bad-split root node, then good-split the resulting
badgoodsize (n-1) node?
We end up with three subarrays, size
1, (n-1)/2, (n-1)/2
Combined cost of splits = n + n-1 = 2n -1 = Θ(n)
No worse than if we had good-split the root node! (n) n
(n-1)/2 n Θ(n −1)
(n-1)/2 (n-1)/2 Θ( n)
(n-1)/2 29 Intuition for the Average Case
Suppose, we alternate lucky and unlucky cases to get an
L(n) = 2U (n / 2) + Θ(n) lucky
U (n) = L(n − 1) + Θ(n) unlucky
we consequently get
L(n) = 2( L(n / 2 − 1) + Θ(n / 2)) + Θ(n)
= 2 L(n / 2 − 1) + Θ (n)
= Θ(n log n) The combination of good and bad splits would result in
T(n) = Θ(n lg n), but with slightly larger constant hidden by
30 Randomized Quicksort
An algorithm is randomized if its behavior is
determined not only by the input but also by values
produced by a random-number generator.
Exchange A[r] with an element chosen at random
from A[p…r] in Partition.
This ensures that the pivot...
View Full Document