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