Você está na página 1de 3

Outline

• Master Method review


Recurrence, Sloppiness • Sloppiness
• Solving recurrence (practice)
• Solving recurrence (tricks)

Recitation 2: Recurrence, sloppiness 1 Recitation 2: Recurrence, sloppiness 2

Master Method Solving Recurrence (Practice)


• Let a ≥ 1, b > 1 and T(n) = aT(n/b) + f(n), where • For each of the following recurrences, give
n/b means either ⎣n/b⎦ or ⎡n/b⎤. Then the asymptotic solution using the Master
1. If f (n) = O(nlogba – ε) for ε > 0, then Theorem (state which case), or else state
T(n) = Θ(nlogba) .
2. If f (n) = Θ(nlogba lgkn) for some constant k ≥ 0, then
that the Master Theorem does not apply
T(n) = Θ(nlogba lgk+1n) . • T(n) = 4T(n/2) + n
3. If f (n) = Ω(nlogba + ε) for some constant ε > 0 and
a f (n/b) ≤ c f (n) for some constant c < 1, then
T(n) = Θ( f (n) ) .

Recitation 2: Recurrence, sloppiness 3 Recitation 2: Recurrence, sloppiness 4

• T(n) = 4T(n/2) + n2 • T(n) = 4T(n/2) + n2 lg n

• T(n) = 4T(n/2) + n3 • T(n) = T(n-2) + n

• T(n) = 3T(n/4) + n lg n • T(n) = 5T(n/2) + n2 lg n

Recitation 2: Recurrence, sloppiness 5 Recitation 2: Recurrence, sloppiness 6

1
• T(n) = 4T(n/4) + n/lg n • T(n) = 2T(n/4) + √n

• T(n) = T(n/4) + lg n • T(n) = 8 T((n - √n)/4) + n2

• T(n) = 2T(n/4) + lg n • T(n) = 2T(n/4) + n0.51

Recitation 2: Recurrence, sloppiness 7 Recitation 2: Recurrence, sloppiness 8

• T(n) = 4T(n/2) + n/lg n • T(n) = T(n/2) + lg(n!)

• T(n) = 8T(n/3) + 2n • T(n) = T(n/2) + n!

• T(n) = 7T(n/3) + n2 • T(n) =16T(n/4) + n2 log 2 n

Recitation 2: Recurrence, sloppiness 9 Recitation 2: Recurrence, sloppiness 10

Change of Variable Drop Lower Order Terms


• An unfamiliar looking recurrence can be
sometimes be made into a familiar one by a • For recurrences like
change of variable T(n) = 2T(n/2 + √n) + Θ(1), note that n
• Example: T(n) = T(√n) + lg n dominates √n.
• Let m = lg n, so n = 2m and √n = 2m/2
• Guess that solution is the same as
• So T(2m) = T(2m/2) + m
S(n) = 2S(n/2) + Θ(1) = Θ(n)
• Define S(m) = T(2m), then
– S(m) = S(m/2) + m • Solution must be verified by the substitution
• So S(m) = Θ(m) method
• Substituting back: T(n) = Θ(lg n)
Recitation 2: Recurrence, sloppiness 11 Recitation 2: Recurrence, sloppiness 12

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

Você também pode gostar