MASTER THEOREM
FOR SOLVING RECURRENCE RELATIONS
BIRLA INSTITUTE OF TECHNOLOGY, MESRA
JAIPUR CAMPUS
Submitted By:
DR. MADHAVI SINHA
Submitted To:
RIDYA GUPTA MCA/25004/22
Introduction to the Master theorem
• The Master theorem is a mathematical tool used to analyse the complexity of
divide-and-conquer algorithms.
• It provides a way to express the time complexity of a recursive algorithm in terms
of its subproblems and their sizes.
• The theorem applies to algorithms that can be represented by the following
recurrence relation:
)
(
)
( n
f
b
n
aT
n
T 







where, a ≥ 1, b > 1, and f(n) > 0
Suppose, there’s a time function of input size n
Let’s say we divide that into b sub-problems, then:
and constant time will be taken for each merge
operation :
Master method
Where:
• T(n) is the running time of the algorithm on input size n
• a is the number of subproblems generated by the algorithm
• n/b is the size of each subproblem
• f(n) is the time spent on the algorithm's work outside of the recursive calls.
• f(n) = θ(nklogpn), k >= 0 and p is a real number
The Master theorem provides a formula to calculate the time complexity of the
algorithm based on the values of a, b, and f(n).
)
(
)
( n
f
b
n
aT
n
T 







Master method
Case 1: If a > bk, then T(n) = θ (nlog
b
a)
Case 2: If a = bk and
• If p < -1, then T(n) = θ (nlog
b
a)
• If p = -1, then T(n) = θ (nlog
b
a.log2n)
• If p > -1, then T(n) = θ (nlog
b
a.logp+1n)
Case 3: If a < bk and
• If p < 0, then T(n) = O (nk)
• If p >= 0, then T(n) = θ (nklogpn)
To solve recurrence relations using Master’s theorem, we compare a with bk. Then, we follow the
following cases-
Problems using the Master theorem:
Problem 1: T(n) = 2T(n/2) + n
a = 2, b = 2, k = 1, p = 0, log22 = 1
Compare nlog
2
2 with f(n) = n
 f(n) = θ(n)  Case 2
 T(n) = θ(n log n)

AOA.pptx

  • 1.
    MASTER THEOREM FOR SOLVINGRECURRENCE RELATIONS BIRLA INSTITUTE OF TECHNOLOGY, MESRA JAIPUR CAMPUS Submitted By: DR. MADHAVI SINHA Submitted To: RIDYA GUPTA MCA/25004/22
  • 2.
    Introduction to theMaster theorem • The Master theorem is a mathematical tool used to analyse the complexity of divide-and-conquer algorithms. • It provides a way to express the time complexity of a recursive algorithm in terms of its subproblems and their sizes. • The theorem applies to algorithms that can be represented by the following recurrence relation: ) ( ) ( n f b n aT n T         where, a ≥ 1, b > 1, and f(n) > 0
  • 3.
    Suppose, there’s atime function of input size n Let’s say we divide that into b sub-problems, then: and constant time will be taken for each merge operation :
  • 5.
    Master method Where: • T(n)is the running time of the algorithm on input size n • a is the number of subproblems generated by the algorithm • n/b is the size of each subproblem • f(n) is the time spent on the algorithm's work outside of the recursive calls. • f(n) = θ(nklogpn), k >= 0 and p is a real number The Master theorem provides a formula to calculate the time complexity of the algorithm based on the values of a, b, and f(n). ) ( ) ( n f b n aT n T        
  • 6.
    Master method Case 1:If a > bk, then T(n) = θ (nlog b a) Case 2: If a = bk and • If p < -1, then T(n) = θ (nlog b a) • If p = -1, then T(n) = θ (nlog b a.log2n) • If p > -1, then T(n) = θ (nlog b a.logp+1n) Case 3: If a < bk and • If p < 0, then T(n) = O (nk) • If p >= 0, then T(n) = θ (nklogpn) To solve recurrence relations using Master’s theorem, we compare a with bk. Then, we follow the following cases-
  • 7.
    Problems using theMaster theorem: Problem 1: T(n) = 2T(n/2) + n a = 2, b = 2, k = 1, p = 0, log22 = 1 Compare nlog 2 2 with f(n) = n  f(n) = θ(n)  Case 2  T(n) = θ(n log n)