Академический Документы
Профессиональный Документы
Культура Документы
1
• T(n) = 4T(n/4) + n/lg n • T(n) = 2T(n/4) + √n
2
Theorem (Sloppiness):
Sloppiness • Suppose that:
1. T(n) and f(n) are monotonically increasing
• What about the merge sort recurrence? 2. T(bi) ≤ f(bi) for all i > 0
– T(n) = T(⎣n/2⎦ ) + T(⎡n/2⎤) + Θ(n) 3. f(n) = O(f(n/b)) - polynomial growth
– Not strictly covered by Master Theorem • Then T(n) = O(f(n))
– In the case where n is a power of 2, no problem: Proof:
• T(n) = 2T(n/2)+Θ(n)
• By case 2 of Master Theorem, T(n) = Θ(n log n)
• T(n) ≤ T(b ⎡logbn⎤) by (1)
– Under what conditions can we say that recurrences such • ≤ f(b ⎡logbn⎤) by (2)
as the merge sort recurrence has the same solution as • ≤ cf(b ⎡logbn⎤-1) by (3)
the simplified version that works for powers of 2??
• ≤ c(f(n)) by (1)
Recitation 2: Recurrence, sloppiness 13 Recitation 2: Recurrence, sloppiness 14
Summary
• Master Theorem
– Memorize - can do most recurrences in your head
• Sloppiness
– Recurrences in algorithms often not defined cleanly
– Only need to be defined cleanly for powers of b
• Tricks for solving recurrences
– Change of variable
– Drop lower order terms
• Akra-Bazzi
– Useful in some cases not covered by Master Theorem
• If these methods don’t work, use your ingenuity,
then verify with substitution method!
Recitation 2: Recurrence, sloppiness 18