The master theorem concerns recurrence relations of the form:
In the application to the analysis of a recursive algorithm, the constants and function take on the following significance:
- n is the size of the problem.
- a is the number of subproblems in the recursion.
- n/b is the size of each subproblem. (Here it is assumed that all subproblems are essentially the same size.)
- f (n) is the cost of the work done outside the recursive calls, which includes the cost of dividing the problem and the cost of merging the solutions to the subproblems.
Case 1
Generic form
If where (using Big O notation)
then:
Example
As one can see from the formula above:
- , so
- , where
Next, we see if we satisfy the case 1 condition:
- .
It follows from the first case of the master theorem that
Case 2
Generic form
If it is true, for some constant k ≥ 0, that:
- where
then:
Example
As we can see in the formula above the variables get the following values:
- where
Next, we see if we satisfy the case 2 condition:
- , and therefore, yes,
So it follows from the second case of the master theorem:
Thus the given recurrence relation T(n) was in Θ(n log n).
Case 3
Generic form
If it is true that:
- where
and if it is also true that:
- for some constant and sufficiently large (often called the regularity condition)
then:
Example
As we can see in the formula above the variables get the following values:
- , where
Next, we see if we satisfy the case 3 condition:
- , and therefore, yes,
The regularity condition also holds:
- , choosing
So it follows from the third case of the master theorem:
Thus the given recurrence relation T(n) was in Θ(n2), that complies with the f (n) of the original formula.
Read full article from Master theorem - Wikipedia, the free encyclopedia