Professional Documents
Culture Documents
Master Theorem Calculator - Gate Vidyalay
Master Theorem Calculator - 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-
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-
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-
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
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-
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)
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-
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.