Master Theorem - Master Theorem Examples - Gate Vidyalay
Master Theorem - Master Theorem Examples - Gate Vidyalay
Master Theorem - Master Theorem Examples - Gate Vidyalay
Master Theorem-
SPONSORED SEARCHES
master method in daa which case is applied when a b k
Learn more
https://www.gatevidyalay.com/masters-theorem-solving-recurrence-relations/ 1/11
10/20/2020 Master Theorem | Master Theorem Examples | Gate Vidyalay
Case-01:
Case-02:
If a = bk and
Case-03:
If a < bk and
Problem-01:
T(n) = 3T(n/2) + n2
Solution-
https://www.gatevidyalay.com/masters-theorem-solving-recurrence-relations/ 2/11
10/20/2020 Master Theorem | Master Theorem Examples | Gate Vidyalay
Then, we have-
a=3
b=2
k=2
p=0
Now, a = 3 and bk = 22 = 4.
Since p = 0, so we have-
T(n) = θ (nklogpn)
T(n) = θ (n2log0n)
Thus,
T(n) = θ (n2)
Problem-02:
Solution-
https://www.gatevidyalay.com/masters-theorem-solving-recurrence-relations/ 3/11
10/20/2020 Master Theorem | Master Theorem Examples | Gate Vidyalay
Then, we have-
a=2
b=2
k=1
p=1
Now, a = 2 and bk = 21 = 2.
Clearly, a = bk.
Since p = 1, so we have-
T(n) = θ (nlogba.logp+1n)
T(n) = θ (nlog22.log1+1n)
Thus,
T(n) = θ (nlog2n)
Problem-03:
Solution-
Then, we have-
https://www.gatevidyalay.com/masters-theorem-solving-recurrence-relations/ 4/11
10/20/2020 Master Theorem | Master Theorem Examples | Gate Vidyalay
a=2
b=4
k = 0.51
p=0
Since p = 0, so we have-
T(n) = θ (nklogpn)
T(n) = θ (n0.51log0n)
Thus,
T(n) = θ (n0.51)
Problem-04:
Solution-
Then, we have-
a = √2
https://www.gatevidyalay.com/masters-theorem-solving-recurrence-relations/ 5/11
10/20/2020 Master Theorem | Master Theorem Examples | Gate Vidyalay
b=2
k=0
p=1
So, we have-
T(n) = θ (nlogba)
T(n) = θ (nlog2√2)
T(n) = θ (n1/2)
Thus,
T(n) = θ (√n)
Problem-05:
Solution-
The given recurrence relation does not correspond to the general form of Master’s theorem.
So, it can not be solved using Master’s theorem.
https://www.gatevidyalay.com/masters-theorem-solving-recurrence-relations/ 6/11
10/20/2020 Master Theorem | Master Theorem Examples | Gate Vidyalay
Problem-06:
Solution-
Then, we have-
a=3
b=3
k=1
p=0
Now, a = 3 and bk = 31 = 3.
Clearly, a = bk.
Since p = 0, so we have-
T(n) = θ (nlogba.logp+1n)
T(n) = θ (nlog33.log0+1n)
T(n) = θ (n1.log1n)
https://www.gatevidyalay.com/masters-theorem-solving-recurrence-relations/ 7/11
10/20/2020 Master Theorem | Master Theorem Examples | Gate Vidyalay
Thus,
T(n) = θ (nlogn)
Problem-07:
Form a recurrence relation for the following code and solve it using Master’s theorem-
1. A(n)
2. {
3. if(n<=1)
4. return 1;
5. else
6. return A(√n);
7. }
Solution-
Let-
n = 2m ……(1)
Then-
T(2m) = T(2m/2) + 1
So, we have-
https://www.gatevidyalay.com/masters-theorem-solving-recurrence-relations/ 8/11
10/20/2020 Master Theorem | Master Theorem Examples | Gate Vidyalay
S(m) = S(m/2) +1
Then, we have-
a=1
b=2
k=0
p=0
Now, a = 1 and bk = 20 = 1.
Clearly, a = bk.
Since p = 0, so we have-
S(m) = θ (mlogba.logp+1m)
S(m) = θ (mlog21.log0+1m)
S(m) = θ (m0.log1m)
Thus,
Now,
S(m) = θ(loglog2n)
Or
T(n) = θ (loglog2n)
Get more notes and other study material of Design and Analysis of Algorithms.
Summary
Publisher Logo
https://www.gatevidyalay.com/masters-theorem-solving-recurrence-relations/ 10/11
10/20/2020 Master Theorem | Master Theorem Examples | Gate Vidyalay
Hand reveals Recursion Tree | Is this your Soul Design & Analysis
your personality Solving Mate? of Algorithms
Recurrence… Notes
Ad Tips and Tricks gatevidyalay.com Ad AstroMary gatevidyalay.com
https://www.gatevidyalay.com/masters-theorem-solving-recurrence-relations/ 11/11