Master Theorem Sections 4.3-4.5
Master Theorem Used to solve a large class of recurrence relations The general form of the recurrence is: Τ 𝑈 𝑜 = 𝑏𝑈 𝑜 𝑐 + 𝑔 𝑜 , where 𝑏 ≥ 1 and 𝑐 > 1 are constants; and 𝑔 𝑜 is an asymptotically positive function
Master Theorem Τ 𝑈 𝑜 = 𝑏𝑈 𝑜 𝑐 + 𝑔 𝑜 1. If 𝑔 𝑜 = 𝑃 𝑜 log 𝑐 𝑏−𝜗 for some constant 𝜗 > 0 , then 𝑈 𝑜 = Θ 𝑜 log 𝑐 𝑏 2. If 𝑔 𝑜 = Θ 𝑜 log 𝑐 𝑏 , then 𝑈 𝑜 = Θ 𝑜 log 𝑐 𝑏 lg 𝑜 = Θ 𝑔 𝑜 lg 𝑜 3. If 𝑔 𝑜 = Ω 𝑜 log 𝑐 𝑏+𝜗 for some constant 𝜗 > 𝑜 0 , and if 𝑏𝑔 𝑐 ≤ 𝑑𝑔 𝑜 for some constant 𝑑 < 1 and all sufficiently large n, then 𝑈 𝑜 = Θ 𝑔 𝑜
Example 1: Merge Sort Τ 𝑈 𝑜 = 2𝑈 𝑜 2 + Θ 𝑜 Τ Master Theorem: 𝑈 𝑜 = 𝑏𝑈 𝑜 𝑐 + 𝑔 𝑜 𝑏 = 2, 𝑐 = 2 𝑔 𝑜 = Θ(𝑜) 𝑔 𝑜 = Θ 𝑜 log 2 2 = Θ 𝑜 Case 2 applies 𝑔 𝑜 = Θ 𝑜 log 𝑜
Example 2 𝑜 𝑈 𝑜 = 16𝑈 4 + 𝑜 𝑔 𝑜 = 𝑜 𝑏 = 16 𝑐 = 4 𝑜 log 𝑐 𝑏 = 𝑜 2 𝑔 𝑜 = 𝑃 𝑜 2−𝜗 , 𝜗 = 0.1 Case 1 applies 𝑈 𝑜 = Θ 𝑜 log 𝑐 𝑏 = Θ 𝑜 2
Example 3 𝑜 2 + 𝑜 2 𝑈 𝑜 = 3𝑈 𝑔 𝑜 = 𝑜 2 𝑏 = 3 𝑐 = 2 𝑜 log 𝑐 𝑏 = 𝑜 1.585… 𝑔 𝑜 = 𝑜 2 = Ω 𝑜 1.585+𝜗 , 𝜗 = 0.2 Regularity condition 𝑜 𝑏𝑔 ≤ 𝑑𝑔 𝑜 , 𝑑 < 1 𝑐 2 𝑜 = 3 4 𝑜 2 ≤ 𝑑𝑔 𝑜 , 𝑑 = 3 3 2 4 Case 3 applies: 𝑈 𝑜 = Θ 𝑜 2
Example 4 𝑜 2 + 2 𝑜 𝑈 𝑜 = 𝑈 𝑔 𝑜 = 2 𝑜 𝑏 = 1 𝑐 = 2 𝑜 log 𝑐 𝑏 = 1 𝑔 𝑜 = 2 𝑜 = Ω 𝑜 0+𝜗 , 𝜗 = 1 (any value works) Regularity condition 𝑜 𝑜 2 ≤ 𝑑2 𝑜 , 𝑑 = 0.5 𝑏𝑔 = 2 𝑐 Case 3: 𝑈 𝑜 = Θ 2 𝑜
Example 5 𝑜 8 − 𝑜 2 𝑈 𝑜 = 64𝑈 𝑔 𝑜 = −𝑜 2 Master Theorem does not apply as 𝑔 𝑜 must be an asymptotically positive function.
Example 6 𝑜 𝑜 𝑈 𝑜 = 2𝑈 2 + log 𝑜 𝑔 𝑜 = 𝑜/ log 𝑜 𝑏 = 2 𝑐 = 2 𝑜 log 𝑐 𝑏 = 𝑜 𝑔 𝑜 = 𝑃 𝑜 log 𝑐 𝑏 𝑔 𝑜 = 𝜕 𝑜 log 𝑐 𝑏−𝜗 , for any +ve value of 𝜗 𝑔 𝑜 ≠ 𝑃 𝑜 log 𝑐 𝑏−𝜗 Master Theorem does not apply
Example 7 𝑈 𝑜 = 2𝑈 𝑜 + 𝑜 2 𝑔 𝑜 = 𝑜 2 𝑏 = 2 𝑐 = 1 Master Theorem does not apply as 𝑐 must be larger than (and not equal to) 1
Example 8 𝑜 𝑈 𝑜 = 𝑈 2 + 𝑜 2 − cos 𝑜 𝑔 𝑜 = 𝑜 2 − cos 𝑜 𝑏 = 1 𝑐 = 2 𝑜 log 𝑐 𝑏 = 1 𝑔 𝑜 = 𝑜 2 − cos 𝑜 = Ω(𝑜 0+𝜗 ) , 𝜗 = 0.5 Regularity condition 𝑜 = 𝑜 2 2 − cos 𝑜 𝑏𝑔 < 𝑑 ⋅ 𝑜 2 − cos 𝑜 ? 𝑐 2 2 − cos 𝑜 2 < 2𝑑 2 − cos 𝑜 ?
Example 8 (cont ’) The previous inequality cannot be true because when 𝑜 = 2𝑗 ⋅ 𝜌 , 𝑗 is an odd integer: 𝜌 LHS= 2 − cos 2𝑗 ⋅ = 3 2 RHS= 2𝑑 2 − cos 2𝑗 ⋅ 𝜌 = 2𝑑 For the inequality to hold 3 ≤ 2𝑑 3 𝑑 ≥ 2 > 1 But the regularity condition requires 𝑑 < 1 Regularity condition does not hold Master theorem does not apply
Recommend
More recommend