0% found this document useful (0 votes)
145 views53 pages

Master Theorem - (Decreasing and Dividing Functions)

The document discusses the Master Theorem, which provides a method for determining the time complexity of recursive algorithms. It states that the Master Theorem is the most useful approach for computing the time complexity of recurrence relations. The Master Theorem can be applied to decreasing functions like decrease-and-conquer algorithms and dividing functions like divide-and-conquer algorithms. It presents examples showing how to apply the Master Theorem to different recurrence relations to determine their time complexities.

Uploaded by

f2021266018
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views53 pages

Master Theorem - (Decreasing and Dividing Functions)

The document discusses the Master Theorem, which provides a method for determining the time complexity of recursive algorithms. It states that the Master Theorem is the most useful approach for computing the time complexity of recurrence relations. The Master Theorem can be applied to decreasing functions like decrease-and-conquer algorithms and dividing functions like divide-and-conquer algorithms. It presents examples showing how to apply the Master Theorem to different recurrence relations to determine their time complexities.

Uploaded by

f2021266018
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 53

Master Theorem

Master Theorem

 Master Theorem is the most useful and easy method to compute the time complexity
function of recurrence relations.

 Recursive functions might get complex if we start calculating its time complexity function
by other commonly used simpler methods.

 Master Theorem is the best method to quickly find the algorithm's time complexity from
its recurrence relation.

The approach was first presented by John Bentley, Dorothea, and James B. Saxe in 1980
Master Theorem

 Master theorem provides an asymptotic analysis for recurrence relations of types that
occur in the analysis of many divide and conquer algorithms.

 The master theorem always yields asymptotically tight bounds to recurrences from divide
and conquer algorithms that partition an input into smaller subproblems of equal sizes
Master Theorem

Master theorem can be applied to:

 Decreasing Functions - Decrease and Conquer Algorithms

 Dividing Functions - Divide and Conquer Algorithms


Master Theorem
(Decreasing Function)
Master Theorem for Decreasing Functions : Decrease and Conquer
We have already seen Master Theorem
T(n) ¿ 𝑇 (𝑛 − 1) + 1 T(n) ¿ 𝒂 𝑇 (𝑛− 𝒃) + f(n)
T(n) ¿ 𝑇 (𝑛 − 1) + n a > 0, b > and f(n) = O(n)
where d ≥ 0
T(n) ¿ 𝑇 (𝑛 − 1) + log n
Case 1:
T(n) ¿ 𝑇 (𝑛 −2) + 1
if a =1 O(n * f(n)) or O(nd+1)
T(n) ¿ 2 𝑇 (𝑛 −1) + 1
Case 2:
T(n) ¿ 2 𝑇 (𝑛 −2) + 1 if a >1 O(f(n) a) or O(nd a)
T(n) ¿ 3 𝑇 (𝑛 −1) + 1 Case 3:
T(n)¿ 2 𝑇 (𝑛 − 1)+ n if a <1 O(f(n)) or O(nd)
Master Theorem for Decreasing Functions Case 1
Example 1:
Master Theorem
T(n)¿ 𝑇 (𝑛 − 1)+ 1
T(n) ¿ 𝒂 𝑇 (𝑛− 𝒃) + f(n)
a=1 f(n) = 1
a > 0, b > 0 , f(n) = O(n) where d, p ≥ 0 =nn
a = number of subproblems
d=p=0 =n n
b = the constant by which the subproblem size is reduced.
d = degree of polynomial
or O(n* f(n))
= O( nd+1 n)
Case 1: if a =1 then O(nd+1 logp n ) = O( n )
or O(f(n)*an/b) = O( n 0+1
n)
Case 2: if a >1 then O(nd logp n a)
or O(f(n)) or
O( n * f(n) ) f(n) = 1
Case 3: if a <1 then O(n log )d p

= O( n )
Master Theorem for Decreasing Functions Case 1
Example 2:
Master Theorem
T(n)¿ 𝑇 (𝑛 − 1)+ n
T(n) ¿ 𝒂 𝑇 (𝑛− 𝒃) + f(n)
a=1 f(n) = n
a > 0, b > 0 , f(n) = O(n) where d, p ≥ 0 =nn
a = number of subproblems
d = 1, p = 0 = n n
b = the constant by which the subproblem size is reduced.
d = degree of polynomial
or O(n* f(n))
Case 1: if a =1 then O(n d+1
log n )
p = O( nd+1 n)
= O( n2 )
or O(f(n)*an/b) = O( n1+1 n)
Case 2: if a >1 then O(nd logp n a)
or O(f(n)) or O( n * f(n) ) f(n) = n
Case 3: if a <1 then O(nd logp)
= O( n2 )
Master Theorem for Decreasing Functions Case 1
Example 3:
Master Theorem
T(n)¿ 𝑇 (𝑛 − 1)+ log n
T(n) ¿ 𝒂 𝑇 (𝑛− 𝒃) + f(n)
a=1 f(n) = log n
a > 0, b > 0 , f(n) = O(n) where d, p ≥ 0 =nn
a = number of subproblems d=0 , p=1 =nn
b = the constant by which the subproblem size is reduced.
d = degree of polynomial
or O(n* f(n))
Case 1: if a =1 then O(n d+1
log n )
p = O( nd+1 n)
= O( nlog n
or O(f(n)*a ) n/b
= O( n 0+1
n)
Case 2: if a >1 then O(nd logp n a)
or O(f(n)) or O( n * f(n) ) f(n) = log n
Case 3: if a <1 then O(nd logp)
= O(n log n)
Master Theorem for Decreasing Functions Case 1
Example 4:
Master Theorem
T(n)¿ 𝑇 (𝑛 − 2)+ 1
T(n) ¿ 𝒂 𝑇 (𝑛− 𝒃) + f(n)
a=1 f(n) = 1
a > 0, b > 0 , f(n) = O(n) where d, p ≥ 0 =nn
a = number of subproblems d=0 , p=0 =nn
b = the constant by which the subproblem size is reduced.
d = degree of polynomial
or O(n* f(n))
Case 1: if a =1 then O(n d+1
log n )
p = O( nd+1 n)
= O( n )
or O(f(n)*a ) n/b
= O( n 0+1
n)
Case 2: if a >1 then O(nd logp n a)
or O(f(n)) or O( n * f(n) ) f(n) = 1
Case 3: if a <1 then O(nd logp)
= O(n)
Master Theorem for Decreasing Functions Case 2
Example 5:
Master Theorem
T(n)¿ 𝟐 𝑇 (𝑛 − 1)+ 1
T(n) ¿ 𝒂 𝑇 (𝑛− 𝒃) + f(n)
a=2 , b=1 f(n) = 1
a > 0, b > 0 , f(n) = O(n) where d, p ≥ 0 =nn
a = number of subproblems d =0 , p =0 =n n
b = the constant by which the subproblem size is reduced.
d = degree of polynomial
or O(n* f(n))
Case 1: if a =1 then O(n d+1
log n )
p = O( nd n an/b)
= O( 2n )
or O(f(n)*an/b) = O( n0 n 2n/1)
Case 2: if a >1 then O(nd logp n a)
or O(f(n)) or O( f(n) *an/b ) f(n) = 1
Case 3: if a <1 then O(nd logp)
= O(2n)
Master Theorem for Decreasing Functions Case 2
Example 6:
Master Theorem
T(n)¿ 𝟐 𝑇 (𝑛 −2)+ 1
T(n) ¿ 𝒂 𝑇 (𝑛− 𝒃) + f(n)
a=2 , b=2 f(n) = 1
a > 0, b > 0 , f(n) = O(n) where d, p ≥ 0 =nn
a = number of subproblems d =0 , p =0 =n n
b = the constant by which the subproblem size is reduced.
d = degree of polynomial
or O(n* f(n))
Case 1: if a =1 then O(n d+1
log n )
p = O( nd n an/b)
= O( 2n/2 )
or O(f(n)*an/b) = O( n0 n 2n/2)
Case 2: if a >1 then O(nd logp n a)
or O(f(n)) or O( f(n) *an/b ) f(n) = 1
Case 3: if a <1 then O(nd logp)
= O(2n/2)
Master Theorem for Decreasing Functions Case 2
Example 7:
Master Theorem
T(n)¿ 𝟑 𝑇 (𝑛 − 1)+ 1
T(n) ¿ 𝒂 𝑇 (𝑛− 𝒃) + f(n)
a=3 , b=1 f(n) = 1
a > 0, b > 0 , f(n) = O(n) where d, p ≥ 0 =nn
a = number of subproblems d =0 , p =0 =n n
b = the constant by which the subproblem size is reduced.
d = degree of polynomial
or O(n* f(n))
Case 1: if a =1 then O(n d+1
log n )
p = O( nd n an/b)
= O( 3n )
or O(f(n)*an/b) = O( n0 n 3n/1)
Case 2: if a >1 then O(nd logp n a)
or O(f(n)) or O( f(n) *an/b ) f(n) = 1
Case 3: if a <1 then O(nd logp)
= O(3n)
Master Theorem for Decreasing Functions Case 2
Example 8:
Master Theorem
T(n)¿ 𝟐 𝑇 (𝑛 − 1)+ n
T(n) ¿ 𝒂 𝑇 (𝑛− 𝒃) + f(n)
a=2 , b=1 f(n) = n
a > 0, b > 0 , f(n) = O(n) where d, p ≥ 0 =nn
a = number of subproblems d =1 , p =0 =n n
b = the constant by which the subproblem size is reduced.
d = degree of polynomial
or O(n* f(n))
Case 1: if a =1 then O(n d+1
log n )
p = O( nd n an/b)
= O( n 2n )
or O(f(n)*an/b) = O( n1 n 2n/1)
Case 2: if a >1 then O(nd logp n a)
or O(f(n)) or O( f(n) *an/b ) f(n) = n
Case 3: if a <1 then O(nd logp)
= O(n 2n)
Master Theorem for Decreasing Functions Case 3
Example 8:
Master Theorem
T(n)¿ 𝟎 . 𝟓 𝑇 ( 𝑛− 1)+ n
T(n) ¿ 𝒂 𝑇 (𝑛− 𝒃) + f(n)
a=0.5 f(n) = n
a > 0, b > 0 , f(n) = O(n) where d, p ≥ 0 =nn
a = number of subproblems d =1 , p =0 =n n
b = the constant by which the subproblem size is reduced.
d = degree of polynomial
or O(n* f(n))
Case 1: if a =1 then O(n d+1
log n )
p = O( nd n)
= O( n )
or O(f(n)*a ) n/b
= O( n n)
1

Case 2: if a >1 then O(nd logp n a)


or O(f(n)) or O( f(n) ) f(n) = n
Case 3: if a <1 then O(nd logp)
= O(n)
Master Theorem
(Dividing Function)
Master Theorem for Dividing Functions : Divide and Conquer

𝒏
T(n)¿ 𝒂 𝑻 ( )+ f(n) T(n) = 𝜽 ( 𝟏)
𝒃

a≥1 : a is the number of subproblems


b>1 : b the factor by which the subproblem size is reduced in each recursive call
n : n is the input size of the problem
𝒏
𝒃 : size of each subproblem (assuming size of each subproblem is same)
: f(n) denotes cost of the work done outside the
f(n) = O(n) where d ≥ 1, p ≥ 1 recursive call, which includes:
d = degree of polynomia  cost of dividing the problem
f(n) denotes amount of time taken at top level of recurrence  cost of merging the solutions
Master Theorem for Dividing Functions : Divide and Conquer

𝒏
T(n)¿ 𝒂 𝑻 ( )+ f(n)
𝒃
where a ≥ 1, b > 1 and

f(n) = O(n) , where d ≥ 1, p ≥ 1

T(n) = 𝜽(𝟏) n is less than some bound k > 0,


the smallest input size that will lead to a recursive call
Master Theorem for Dividing Functions : Divide and Conquer
a < bd
𝒏 logb a < logb bd
T(n)¿ 𝒂 𝑻 ( )+ f(n) T(n) = 𝜽 ( 𝟏) logb a < d logb b
𝒃
logb a < d
where a ≥ 1, b > 1 and f(n) = O(n) , where d ≥ 1, p ≥ 1
logb a = log a / log b

Case 1: If a > bd , (or logb a > d) Case 2: If a = bd , (or logb a = d)

then T(n) = Θ()  If p > -1, then T(n) = Θ(logp+1 n )

 If p = -1, then T(n) = Θ(log log n )


Case 3: If a < bd , (or logb a < d)
 If p < -1, then T(n) = Θ ( )
 If p ≥ 0, then T(n) = Θ(nd logp n)

 If p < 0, then T(n) = Θ(nd)


Master Theorem for Dividing Functions : Divide and Conquer

Example 1: Here a = 3 , b = 2
𝒏
T(n)¿ 𝟑 𝑻 ( )+ n and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n = n1
Give us d=1,p=0
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
3 21 log2 3 1
Case 2: If a = bd , (or logb a = d) 3>2 log2 21.58 1
a > bd 1.58 log2 2 1
Case 3: If a < bd , (or logb a < d) Case 1 1.58 > 1
Master Theorem for Dividing Functions : Divide and Conquer

Example 1: Here a = 3 , b = 2
𝒏
T(n)¿ 𝟑 𝑻 ( )+ n and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n = n1
Give us d=1,p=0
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
3 21 log2 3 1
Case 2: If a = bd , (or logb a = d) 3>2 log2 21.58 1
a > bd 1.58 log2 2 1
Case 3: If a < bd , (or logb a < d) Case 1 1.58 > 1
Master Theorem for Dividing Functions : Divide and Conquer

Example 1: Here a = 3 , b = 2
𝒏
T(n)¿ 𝟑 𝑻 ( )+ n and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n = n1
Give us d=1,p=0
Case 1: If a > bd , (or logb a > d)

then T(n) = Θ() T(n) = Θ()

= Θ()

= Θ()
Master Theorem for Dividing Functions : Divide and Conquer

Example 1b: Here a = 8 , b = 2


𝒏
T(n)¿ 𝟖 𝑻 ( )+ n2 and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n2 = n2
Give us d=2,p=0
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
8 22 log2 8 2
Case 2: If a = bd , (or logb a = d) 8>4 log2 23 2
a > bd 3 log2 2 2
Case 3: If a < bd , (or logb a < d) Case 1 3 > 2
Master Theorem for Dividing Functions : Divide and Conquer

Example 1b: Here a = 8 , b = 2


𝒏
T(n)¿ 𝟖 𝑻 ( )+ n2 and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n2 = n2
Give us d=2,p=0
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
8 22 log2 8 2
Case 2: If a = bd , (or logb a = d) 8>4 log2 23 2
a > bd 3 log2 2 2
Case 3: If a < bd , (or logb a < d) Case 1 3 > 2
Master Theorem for Dividing Functions : Divide and Conquer

Example 1b: a=8,b=2


𝒏
T(n)¿ 𝟖 𝑻 ( )+ n2 and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n2 = n2
Give us d=2,p=0
Case 1: If a > bd , (or logb a > d)

8 = 23
then T(n) = Θ()
log2 8 = log2 23
T(n) = Θ() = Θ() Required Answer log2 8 = 3 log2 2
log2 8 = 3
Master Theorem for Dividing Functions : Divide and Conquer

Example 2(i): Here a = 1 , b = 2


𝒏
T(n)¿ 𝑻 ( )+ 1 and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = 1 = n0
Give us d=0,p=0
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
1 20 log2 1 0
Case 2: If a = bd , (or logb a = d) 1=1 log2 20 0
a = bd 0 log2 2 0
Case 3: If a < bd , (or logb a < d) Case 2 0 = 0
Master Theorem for Dividing Functions : Divide and Conquer

Example 2(i): Here a = 1 , b = 2


𝒏
T(n)¿ 𝑻 ( )+ 1 and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = 1 = n0
Give us d=0,p=0
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
1 20 log2 1 0
Case 2: If a = bd , (or logb a = d) 1=1 log2 20 0
a = bd 0 log2 2 0
Case 3: If a < bd , (or logb a < d) Case 2 0 = 0
Master Theorem for Dividing Functions : Divide and Conquer

Example 2(i): Here a = 1 , b = 2


𝒏
T(n)¿ 𝑻 ( )+ 1 and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = 1 = n0
Give us d=0,p=0
Case 2: If a = bd , (or logb a = d)

 If p > -1, then T(n) = Θ(logp+1 n )

 If p = -1, then T(n) = Θ(log log n )

 If p < -1, then T(n) = Θ ( )


Master Theorem for Dividing Functions : Divide and Conquer

Example 2(i): Here a = 1 , b = 2


𝒏
T(n)¿ 𝑻 ( )+ 1 and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = 1 = n0
Give us d=0,p=0 1 = 20
Case 2: If a = bd , (or logb a = d) log2 1 = log2 20
log2 1 = 0 log2 2
 If p > -1, then T(n) = Θ(logp+1 n ) log2 1 = 0
T(n) = Θ( logp+1 n )
 If p = -1, then T(n) = Θ(log log n )
= Θ( log0+1 n )
 If p < -1, then T(n) = Θ ( )
= Θ( log n )
= Θ(log n ) Required Answer
Master Theorem for Dividing Functions : Divide and Conquer

Example 2(i)a: Here a = 2 , b = 2


𝒏
T(n)¿ 𝟐 𝑻 ( )+ n and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n = n1
Give us d=1,p=0
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
2 21 log2 2 1
Case 2: If a = bd , (or logb a = d) 2=2 log2 21 1
a = bd 1 log2 2 1
Case 3: If a < bd , (or logb a < d) Case 2 1 = 1
Master Theorem for Dividing Functions : Divide and Conquer

Example 2(i)a: Here a = 2 , b = 2


𝒏
T(n)¿ 𝟐 𝑻 ( )+ n and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n = n1
Give us d=1,p=0
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
2 21 log2 2 1
Case 2: If a = bd , (or logb a = d) 2=2 log2 21 1
a = bd 1 log2 2 1
Case 3: If a < bd , (or logb a < d) Case 2 1 = 1
Master Theorem for Dividing Functions : Divide and Conquer

Example 2(i)a: Here a = 2 , b = 2


𝒏
T(n)¿ 𝟐 𝑻 ( )+ n and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n = n1
Give us d=1,p=0
Case 2: If a = bd , (or logb a = d)

 If p > -1, then T(n) = Θ(logp+1 n )

 If p = -1, then T(n) = Θ(log log n )

 If p < -1, then T(n) = Θ ( )


Master Theorem for Dividing Functions : Divide and Conquer

Example 2(i)a: Here a = 2 , b = 2


𝒏
T(n)¿ 𝟐 𝑻 ( )+ n and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n = n1
Give us d=1,p=0
Case 2: If a = bd , (or logb a = d)

 If p > -1, then T(n) = Θ(logp+1 n ) T(n) = Θ( logp+1 n )


 If p = -1, then T(n) = Θ(log log n ) = Θ( log0+1 n )

 If p < -1, then T(n) = Θ ( ) = Θ(log n ) Required Answer


Master Theorem for Dividing Functions : Divide and Conquer

Example 2(i)b: Here a = 4 , b = 2


𝒏
T(n)¿ 𝟒 𝑻 ( )+ n2 and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n2 = n2
Give us d=2,p=0
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
4 22 log2 4 2
Case 2: If a = bd , (or logb a = d) 4=4 log2 22 2
a = bd 2 log2 2 2
Case 3: If a < bd , (or logb a < d) Case 2 2 = 2
Master Theorem for Dividing Functions : Divide and Conquer

Example 2(i)b: Here a = 4 , b = 2


𝒏
T(n)¿ 𝟒 𝑻 ( )+ n2 and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n2 = n2
Give us d=2,p=0
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
4 22 log2 4 2
Case 2: If a = bd , (or logb a = d) 4=4 log2 22 2
a = bd 2 log2 2 2
Case 3: If a < bd , (or logb a < d) Case 2 2 =2
Master Theorem for Dividing Functions : Divide and Conquer

Example 2(i)b: Here a = 4 , b = 2


𝒏
T(n)¿ 𝟒 𝑻 ( )+ n2 and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n2 = n2
Give us d=2,p=0
Case 2: If a = bd , (or logb a = d)

 If p > -1, then T(n) = Θ(logp+1 n )

 If p = -1, then T(n) = Θ(log log n )

 If p < -1, then T(n) = Θ ( )


Master Theorem for Dividing Functions : Divide and Conquer

Example 2(i)b: Here a = 4 , b = 2


𝒏
T(n)¿ 𝟒 𝑻 ( )+ n2 and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n2 = n2
Give us d=2,p=0 4 = 22
Case 2: If a = bd , (or logb a = d) log2 4 = log2 22
log2 4 = 2 log2 2
 If p > -1, then T(n) = Θ(logp+1 n ) log2 4 = 2
 If p = -1, then T(n) = Θ(log log n ) T(n) = Θ( logp+1 n )

 If p < -1, then T(n) = Θ ( ) = Θ( log0+1 n )

= Θ( log n ) Required Answer


Master Theorem for Dividing Functions : Divide and Conquer

Example 2(ii): Here a = 2 , b = 2


𝒏 and
T(n)¿ 𝟐 𝑻 ( )+
𝟐
f(n) = O(n) = = n1
a ≥ 1, b > 1, f(n) = O(n)
Give us d = 1 , p = -1
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
2 21 log2 2 1
Case 2: If a = bd , (or logb a = d) 2=2 log2 21 1
a = bd 1 log2 2 1
Case 3: If a < bd , (or logb a < d) Case 2 1 = 1
Master Theorem for Dividing Functions : Divide and Conquer

Example 2(ii): Here a = 2 , b = 2


𝒏 and
T(n)¿ 𝟐 𝑻 ( )+
𝟐
f(n) = O(n) = = n1
a ≥ 1, b > 1, f(n) = O(n)
Give us d = 1 , p = -1
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
2 21 log2 2 1
Case 2: If a = bd , (or logb a = d) 2=2 log2 21 1
a = bd 1 log2 2 1
Case 3: If a < bd , (or logb a < d) Case 2 1 = 1
Master Theorem for Dividing Functions : Divide and Conquer

Example 2(ii): Here a = 2 , b = 2


𝒏 and
T(n)¿ 𝟐 𝑻 ( )+
𝟐
f(n) = O(n) = = n1
a ≥ 1, b > 1, f(n) = O(n)
Give us d = 1 , p = -1
Case 2: If a = bd , (or logb a = d)

 If p > -1, then T(n) = Θ(logp+1 n )

 If p = -1, then T(n) = Θ(log log n )

 If p < -1, then T(n) = Θ ( )


Master Theorem for Dividing Functions : Divide and Conquer

Example 2(ii): Here a = 2 , b = 2


𝒏 and
T(n)¿ 𝟐 𝑻 ( )+
𝟐
f(n) = O(n) = = n1
a ≥ 1, b > 1, f(n) = O(n)
Give us d = 1 , p = -1
Case 2: If a = bd , (or logb a = d)

 If p > -1, then T(n) = Θ(logp+1 n )


T(n) = Θ(log log n )
 If p = -1, then T(n) = Θ(log log n )
= Θ(log log n )
 If p < -1, then T(n) = Θ ( )
= Θ(log log n )
Master Theorem for Dividing Functions : Divide and Conquer

Example 2(iii): Here a = 16 , b = 4


𝒏 and
T(n)¿ 𝟏𝟔 𝑻 ( )+
𝟒
f(n) = O(n) = = n2
a ≥ 1, b > 1, f(n) = O(n)
Give us d = 2 , p = -2
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
16 42 log4 16 2
Case 2: If a = bd , (or logb a = d) 16 = 16 log4 42 2
a = bd 2 log4 4 2
Case 3: If a < bd , (or logb a < d) Case 2 2 = 2
Master Theorem for Dividing Functions : Divide and Conquer

Example 2(iii): Here a = 16 , b = 4


𝒏 and
T(n)¿ 𝟏𝟔 𝑻 ( )+
𝟒
f(n) = O(n) = = n2
a ≥ 1, b > 1, f(n) = O(n)
Give us d = 2 , p = -2
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
16 42 log4 16 2
Case 2: If a = bd , (or logb a = d) 16 = 16 log4 42 2
a = bd 2 log4 4 2
Case 3: If a < bd , (or logb a < d) Case 2 2 = 2
Master Theorem for Dividing Functions : Divide and Conquer

Example 2(iii): Here a = 16 , b = 4


𝒏 and
T(n)¿ 𝟏𝟔 𝑻 ( )+
𝟒
f(n) = O(n) = = n2
a ≥ 1, b > 1, f(n) = O(n)
Give us d = 2 , p = -2
Case 2: If a = bd , (or logb a = d)

 If p > -1, then T(n) = Θ(logp+1 n )

 If p = -1, then T(n) = Θ(log log n )

 If p < -1, then T(n) = Θ ( )


Master Theorem for Dividing Functions : Divide and Conquer

Example 2(iii): Here a = 16 , b = 4


𝒏 and
T(n)¿ 𝟏𝟔 𝑻 ( )+
𝟒
f(n) = O(n) = = n2
a ≥ 1, b > 1, f(n) = O(n)
Give us d = 2 , p = -2
Case 2: If a = bd , (or logb a = d)

 If p > -1, then T(n) = Θ(logp+1 n ) T(n) = Θ ( )


 If p = -1, then T(n) = Θ(log log n ) =Θ()
 If p < -1, then T(n) = Θ ( )
=Θ()
Master Theorem for Dividing Functions : Divide and Conquer

Example 3(i): Here a = 1 , b = 2


𝒏
T(n)¿ 𝑻 ( )+ n and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n = n1
Give us d=1,p=0
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
1 21 log2 1 1
Case 2: If a = bd , (or logb a = d) 1<2 log2 20 1
a < bd 0 log2 2 1
Case 3: If a < bd , (or logb a < d) Case 3 0 < 1
Master Theorem for Dividing Functions : Divide and Conquer

Example 3(i): Here a = 1 , b = 2


𝒏
T(n)¿ 𝑻 ( )+ n and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n = n1
Give us d=1,p=0
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
1 21 log2 1 1
Case 2: If a = bd , (or logb a = d) 1<2 log2 20 1
a < bd 0 log2 2 1
Case 3: If a < bd , (or logb a < d) Case 3 0 < 1
Master Theorem for Dividing Functions : Divide and Conquer

Example 3(i): Here a = 1 , b = 2


𝒏
T(n)¿ 𝑻 ( )+ n and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n = n1
Give us d=1,p=0

Case 3: If a < bd , (or logb a < d)

 If p ≥ 0, then T(n) = Θ(nd logp n)

 If p < 0, then T(n) = Θ(nd)


Master Theorem for Dividing Functions : Divide and Conquer

Example 3(i): Here a = 1 , b = 2


𝒏
T(n)¿ 𝑻 ( )+ n and
𝟐
a ≥ 1, b > 1, f(n) = O(n) f(n) = O(n) = n = n1
Give us d=1,p=0

Case 3: If a < bd , (or logb a < d)

 If p ≥ 0, then T(n) = Θ(nd logp n) T(n) = Θ(nd logp n)

 If p < 0, then T(n) = Θ(n ) d = Θ(n1 log0 n)

= Θ( ) Required Answer
Master Theorem for Dividing Functions : Divide and Conquer

Example 3(ii): Here a = 2 , b = 2


𝒏 and
T(n)¿ 𝟐 𝑻 ( )+
𝟐
f(n) = O(n) = = n3
a ≥ 1, b > 1, f(n) = O(n)
Give us d = 3 , p = -1
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
2 23 log2 2 3
Case 2: If a = bd , (or logb a = d) 2<8 log2 21 3
a < bd 1 log2 2 3
Case 3: If a < bd , (or logb a < d) Case 3 1 < 3
Master Theorem for Dividing Functions : Divide and Conquer

Example 3(ii): Here a = 2 , b = 2


𝒏 and
T(n)¿ 𝟐 𝑻 ( )+
𝟐
f(n) = O(n) = = n3
a ≥ 1, b > 1, f(n) = O(n)
Give us d = 3 , p = -1
Case 1: If a > bd , (or logb a > d)
a bd or logb a d
2 23 log2 2 3
Case 2: If a = bd , (or logb a = d) 2<8 log2 21 3
a < bd 1 log2 2 3
Case 3: If a < bd , (or logb a < d) Case 3 1 < 3
Master Theorem for Dividing Functions : Divide and Conquer

Example 3(ii): Here a = 2 , b = 2


𝒏 and
T(n)¿ 𝟐 𝑻 ( )+
𝟐
f(n) = O(n) = = n3
a ≥ 1, b > 1, f(n) = O(n)
Give us d = 3 , p = -1

Case 3: If a < bd , (or logb a < d)

 If p ≥ 0, then T(n) = Θ(nd logp n)

 If p < 0, then T(n) = Θ(nd)


Master Theorem for Dividing Functions : Divide and Conquer

Example 3(ii): Here a = 2 , b = 2


𝒏 and
T(n)¿ 𝟐 𝑻 ( )+
𝟐
f(n) = O(n) = = n3
a ≥ 1, b > 1, f(n) = O(n)
Give us d = 3 , p = -1

Case 3: If a < bd , (or logb a < d)


T(n) = Θ(nd)
 If p ≥ 0, then T(n) = Θ(nd logp n)
T(n) = Θ(n3)
 If p < 0, then T(n) = Θ(nd)

You might also like