This preview shows page 1. Sign up to view the full content.
Unformatted text preview: c(n - 1)2 + Θ(n) ≤ cn2 - 2c(n - 1) + 1 + Θ(n) ≤ cn2
Therefore, the worst case running time is Θ(n2)
23 Best Case Partition
When the partitioning procedure produces two
regions of size n/2, we get the a balanced partition
with best case performance:
T(n) = 2T(n/2) + Θ(n) = Θ(n lg n)
Average complexity is also Θ(n lg n)
Average 24 Best Case Partitioning 25 Average Case
Assuming random input, average-case running time
is much closer to Θ(n lg n) than Θ(n2)
First, a more intuitive explanation/example:
Suppose that partition() always produces a 9-to-1
proportional split. This looks quite unbalanced!
The recurrence is thus:
T(n) = T(9n/10) + T(n/10) + Θ(n) = Θ(n lg n)!
How deep will the recursion go? 26 Average Case
T (n) = T (n /10) + T (9n /10) + Θ( n) = Θ( n log n)! For a split of proportionality α, where 0≤α≤½, the minimum depth
of the tree is - lg n / lg α & the maximum depth is - lg n / lg(1-α).
log2n = log10n/log102
27 Average Case
Intuitively, a real-life run of quicksort will produce a
mix of “bad” and “good” splits
Randomly distributed among the recursion tree
Pretend for intuition that they alternate between
best-case (n/2:n/2) and worst-case (n-1:1) 28 Average Case
View Full Document