Master theorem (analysis of algorithms): Difference between revisions
m Reverted edits by 202.88.147.8 (talk) to last version by Wazow |
→Generic Form: ambigious, could have been a,\epsilon |
||
Line 18: | Line 18: | ||
If it is true that: |
If it is true that: |
||
:<math>f(n) \in O\left( n^{\log_b a - \epsilon} \right)</math> for |
:<math>f(n) \in O\left( n^{\log_b a - \epsilon} \right)</math> for some constant <math>\epsilon > 0</math> |
||
it follows that: |
it follows that: |
Revision as of 18:35, 10 June 2006
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.
Generic Form
Given a relation of the form:
- Failed to parse (Conversion error. Server ("https://wikimedia.org/enwiki/api/rest_") reported: "Cannot get mml. TeX parse error: Undefined control sequence \emph"): {\displaystyle T(n)=aT\left({\frac {n}{b}}\right)+f(n)\;\;\;\;{\emph {where}}\;\;a\geq 1,b>1}
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:
Case 1
Generic Form
If it is true that:
- for some constant
it follows that:
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³)
Case 2
Generic Form
If it is true that:
it follows that:
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))
Case 3
Generic Form
If it is true that:
- for a
and if it is also true that:
- for a and sufficiently large n
it follows that:
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²), what complies with the f(n) of the original formula.
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 0262032937. Sections 4.3 (The master method) and 4.4 (Proof of the master theorem), pp.73–90.