You are on page 1of 17

Master’s Theorem

Lecture 6
The master method
applies to recurrences ofT(n) = a T(n/b) + f (n) ,
the form

The master
theorem where a >= 1, b > 1, and f is asymptotically
positive.
• There are three cases defined by the base master
theorem [1].
• We will first use these basic rules to find solution to
the recurrence relation. That is, find the complexity
for a given recurrence relation.
Important
points

•[1]. Cormen, Thomas H., et al. Introduction to


algorithms. MIT press, 2009.
All Rules

1. f (n) = O(nlogba – e) for some constant e > 0.


Solution: T(n) = Q(nlogba) .

2. f (n) = Q(nlogba lgkn) for some constant k ³ 0.


Solution: T(n) = Q(nlogba lgk+1n) .

3. f (n) = W(nlogba + e) for some constant e > 0


and f (n) satisfies the regularity condition that a f (n/b) £ c f (n) for some constant c < 1.
Solution: T(n) = Q( f (n) ) .
Examples
1. f (n) = O(nlogba – e) for some constant e > 0.
Solution: T(n) = Q(nlogba) .

T(n) = 4T(n/2) + n
a = 4, b = 2  nlogba = n2; f (n) = n. 2. f (n) = Q(nlogba lgkn) for some constant k ³ 0.
CASE 1: f (n) = O(n2 – e) for e = 1. Solution: T(n) = Q(nlogba lgk+1n) .
 T(n) = Q(n2).
3. f (n) = W(nlogba + e) for some constant e > 0.
T(n) = 4T(n/2) + n2 and f (n) satisfies the regularity condition that a f
a = 4, b = 2  nlogba = n2; f (n) = n2. (n/b) £ c f (n) for some constant c < 1.
CASE 2: f (n) = Q(n2lg0n), that is, k = 0. Solution: T(n) = Q( f (n) ) .
 T(n) = Q(n2lg n).
Examples
1. f (n) = O(nlogba – e) for some constant e > 0.
Solution: T(n) = Q(nlogba) .
T(n) = 4T(n/2) + n3
a = 4, b = 2  nlogba = n2; f (n) = n3.
CASE 3: f (n) = W(n2 + e) for e = 1
and 4(n/2)3 £ cn3 (reg. cond.) for c = 1/2. 2. f (n) = Q(nlogba lgkn) for some constant k ³ 0.
 T(n) = Q(n3). Solution: T(n) = Q(nlogba lgk+1n) .

T(n) = 4T(n/2) + n2/lg n 3. f (n) = W(nlogba + e) for some constant e > 0.


a = 4, b = 2  nlogba = n2; f (n) = n2/lg n. and f (n) satisfies the regularity condition that
Master method does not apply. a f (n/b) £ c f (n) for some constant c < 1.
Solution: T(n) = Q( f (n) ) .
non-polynomial difference between f(n) and nlogba
Important point

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


a = 4, b = 2  nlogba = n2; f (n) = n2/lg n.
Master method does not apply.

We faced a situation in the example given above. That is, no rule of master’s theorem was
applicable here.

To fix this, we can use the advanced version of the master’s theorem.
Extended Version of
Master’s theorem
Master Theorem Cases
)
a > 0, b > 1, k ≥ 0

To use the master method, you will need to memorize three cases:
Case 1: if
Case 2: if

Case 3: if

• ()
Example
𝑇 )
( 𝑛 )=9 𝑇 ( 𝑛
3 )
a > 0, b > 1, k ≥ 0
+ 𝑛

To use the master method, you will need to memorize three cases:
Case 1: if
Case 2: if

Case 3: if

• ()
Example
𝑇 ( 𝑛 )=𝑇
) ( 2 𝑛
3
a > 0, b > 1, k ≥ 0
)+ 1
To use the master method, you will need to memorize three cases:
Case 1: if
Case 2: if

Case 3: if

• ()
Example
𝑇 ( 𝑛 ) =3 𝑇)
( 𝑛
4 )+ 𝑛𝑙𝑜𝑔𝑛
a > 0, b > 1, k ≥ 0

To use the master method, you will need to memorize three cases:
Case 1: if
Case 2: if

Case 3: if

• ()
Example
𝑇 ( 𝑛 ) =2 𝑇)
( 𝑛
2 )+ 𝑛𝑙𝑜𝑔𝑛
a > 0, b > 1, k ≥ 0

To use the master method, you will need to memorize three cases:
Case 1: if
Case 2: if

Case 3: if

• ()
Example
𝑇 )
( 𝑛 )=2 𝑇 ( 𝑛
2 )+ 𝑛
a > 0, b > 1, k ≥ 0

To use the master method, you will need to memorize three cases:
Case 1: if
Case 2: if

Case 3: if

• ()
Example
𝑇 )
( 𝑛 )=8 𝑇 ( 𝑛
2 ) + 𝑛2
a > 0, b > 1, k ≥ 0

To use the master method, you will need to memorize three cases:
Case 1: if
Case 2: if

Case 3: if

• ()
Example
𝑇 )
( 𝑛 )=7 𝑇 ( 𝑛
2 ) + 𝑛2
a > 0, b > 1, k ≥ 0

To use the master method, you will need to memorize three cases:
Case 1: if
Case 2: if

Case 3: if

• ()
Thank You

You might also like