Master theorem
From Wikipedia, the free encyclopedia
In the analysis of algorithms, the master theorem, which is a specific case of the Akra-Bazzi theorem, provides a cookbook solution in asymptotic terms for recurrence relations of types that occur in practice. It was popularized by the canonical algorithms textbook Introduction to Algorithms by Cormen, Leiserson, Rivest, and Stein, which introduces and proves it in sections 4.3 and 4.4, respectively. Nevertheless, not all recurrence relations can be solved with the use of the master theorem.
Contents |
[edit] Generic Form
Given a relation of the form:
where
- a = the number of subproblems in the recursion,
- 1/b = the portion of the original problem represented by each sub-problem
- f(n) = the cost of dividing the problem + the cost of merging the solution
It is possible to determine an asymptotic tight bound according to these three cases:
[edit] Case 1
[edit] Generic Form
If it is true that:
- for some constant ε > 0
it follows that:
[edit] Example
As you can see in the formula above the variables get the following values:
- , , ,
Now you have to check that the following equation holds:
If you insert the values from above, you get:
If you choose ε = 1, you get:
Since this equation holds, the first case of the master theorem applies to the given recurrence relation, thus resulting in the conclusion:
If you insert the values from above, you finally get:
Thus the given recurrence relation T(n) was in Θ(n³)
[edit] Case 2
[edit] Generic Form
If it is true that:
it follows that:
[edit] Example
As you can see in the formula above the variables get the following values:
- , , ,
Now you have to check that the following equation holds:
If you insert the values from above, you get:
Since this equation holds, the second case of the master theorem applies to the given recurrence relation, thus resulting in the conclusion:
If you insert the values from above, you finally get:
Thus the given recurrence relation T(n) was in Θ(nlog(n))
[edit] Case 3
[edit] Generic Form
If it is true that:
- for a ε > 0
and if it is also true that:
- for a c < 1 and sufficiently large n
it follows that:
[edit] Example
As you can see in the formula above the variables get the following values:
- , , ,
Now you have to check that the following equation holds:
If you insert the values from above, and choose ε = 1, you get:
Since this equation holds, you have to check the second Condition, namely if it is true that:
If you insert once more the values from above, you get:
If you choose , it is true that:
So it follows:
If you insert once more the necessary values, you get:
Thus the given recurrence relation T(n) was in Θ(n²), that complies with the f(n) of the original formula.
[edit] References
- Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Sections 4.3 (The master method) and 4.4 (Proof of the master theorem), pp.73–90.
[edit] External Links
- Stony Brook CS Dept Notes for an explanation of why the Master Theorem works