Improvised Master's theorem in Design and Analysis of Algorithm
.Introduction to Master's Theorem
.Master's Theorem Cases
.Problem Statement
.Solution
.Conclusion
2. INTRODUCTION:
⢠Masterâs Theorem is a Popular method for solving the recurrence
relations.
⢠It is used to compute the complexity of a given divide and conquer
problem in asymptotic time.
⢠In divide and conquer problem we have three steps:
ďDivide a large problem into smaller subproblems;
ďRecursively solve each subproblem, then
ďCombine solutions of the subproblems to solve the original
problem.
2
3. The form of the recurrence relation of the masterâs theorem is:
T (n) = aT (n/b) + f(n)
where a ⼠1 and b > 1 are constants and f(n) is an asymptotically
positive function.
In above equation:
ď n = problem size
ď a = number of sub problems
ď n/b = size of each sub problem
ď f (n) = cost of the work done outside the recursive calls
3
4. Masterâs Theorem cases:
⢠If T (n) = aT (n/b) + O(nd) where d>=0, then
Example:
T(n) = 4T(n/2) + n
a = 4, b=2, f(n) = n1, so d = 1
logb a ----> log2 4 = 2
d < logba
1<2
so,
n = O (nlog2 4)
= O (n2)
4
5. PROBLEM STATEMENT:
The earlier used theorem has some limitations. Some equations could not be solved
using the original masterâs theorem.
Here are some examples:
ďT(n)= 0.5T(n/2) + n
In this equation a<1. The number of subproblems is 0.5 whereas there needs to be
at least 1 subproblem.
ďT(n)= 2T(n/2) + n/log n
Master theorem apply only for polynomial, the difference here is not polynomial but
logarithmic.
ďT(n)= 2n T(n/2) + nn
Now in this case we can see that âaâ is not a constant therefore masterâs theorem
wonât be applied.
So, to resolve such problems the masterâs theorem has been revised.
5
6. SOLUTION:
T(n)=aT(n/b) + θ (nd logp n)
(a>=1, b>=1, d>=0 and p is a real number)
⢠Case 1:
If d < logb a, then T(n) = θ (nlogb a)
⢠Case 2:
If d = logb a
ď If p > -1 then, T(n) = θ (nd logp+1 n)
ď If p = -1 then, T(n) = θ (nd log log n)
ď If p < -1 then, T(n) = θ (nd)
⢠Case 3:
If d > logb a
ď If p >= 0 then, T(n) = θ (nd logp n)
ď If p < 0 then, T(n) = O (nd)
6
7. The proposed solution is used to solve the problem like:
Example:
T(n) = 64T (n/8) + n2 log n
Now we will compare the above equation with proposed format we got.
a = 64, b = 8, d = 2, p = 1
Letâs compute logba: log8 64 = 2
2 = 2
logba = d
So, it satisfies the 2nd case i.e T(n) = θ (nd logp+1 n)
Therefore, the solution is θ (n2 log2 n)
7
8. Hereâs another example:
T(n)= 2T(n/2) + n/log n
Now we will compare the above equation with proposed format we got.
a = 2, b = 2, d = 1, p = -1;
Letâs compute logba: log2 2 = 1
1 = 1
logba = d
So, it satisfies the 2nd case i.e T(n) = θ (nd loglog n)
Therefore the solution is θ (n loglog n)
8
9. CONCLUSION:
⢠Those equations that could not be solved using the original masterâs
method but after the relaxation of the constraints they can be solved
using the new approach.
⢠It also helps us to reduce the time complexity in comparison if the
relation is solved using iterative and substitution method.
⢠The proposed method is able to relax some of the constraints of the
original method.
9