Master Theorem - (Decreasing and Dividing Functions)
Master Theorem - (Decreasing and Dividing Functions)
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
= 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
𝒏
T(n)¿ 𝒂 𝑻 ( )+ f(n) T(n) = 𝜽 ( 𝟏)
𝒃
𝒏
T(n)¿ 𝒂 𝑻 ( )+ f(n)
𝒃
where a ≥ 1, b > 1 and
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)
= Θ()
= Θ()
Master Theorem for Dividing Functions : Divide and Conquer
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
= Θ( ) Required Answer
Master Theorem for Dividing Functions : Divide and Conquer