The Master Method for Solving Recurrences
The Master Method for Solving Recurrences
Introduction
When analyzing Divide and Conquer algorithms, we often obtain recurrence relations of the form
Instead of solving every recurrence using substitution or recursion trees, researchers introduces the Master Method, which provides a "cookbook" method for solving many commonly occurring recurrences. Once the three cases are memorized, many divide-and-conquer recurrences can be solved quickly.
Motivation
Many Divide and Conquer algorithms have recurrence relations of the form
Examples include
- Merge Sort
- Binary Search
- Strassen Matrix Multiplication
- Karatsuba Multiplication
- Closest Pair of Points
Instead of solving these recurrences by
- substitution,
- iteration, or
- recursion tree,
we can often apply the Master Theorem, which directly gives the asymptotic running time.
General Form
The Master Theorem applies to recurrences of the form
where
- is the number of recursive subproblems,
- is the factor by which the problem size is reduced,
- is the work done outside the recursive calls (divide and combine).
Meaning of Each Parameter
Suppose
Then
- (two recursive calls),
- (each subproblem has size
- (linear merge cost).
The Master Theorem
For
where
compare the driving function with the watershed function
The result depends on which function grows faster.
Procedure for Applying the Master Theorem
For every recurrence:
-
Write it in the form
- Identify , , and the driving function .
-
Compute the watershed function
- Compare with the watershed function.
- Determine whether Case 1, Case 2, or Case 3 applies.
- Verify the regularity condition if you are using Case 3.
- Write the asymptotic solution.
The Watershed Function
The watershed function:
This function is the reference against which the driving function is compared.
Why is it called the Watershed Function?
Think of a watershed as a dividing line.
If
- is smaller, Case 1 applies.
- is approximately equal, Case 2 applies.
- is larger, Case 3 applies.
Thus the watershed function separates the three cases.
Case 1
Condition
If
for some
then
Interpretation
The recursive work dominates.
The divide/combine work is much smaller.
The cost of the leaves dominates the recursion tree.
Example 1
Step 1
Identify
Step 2
Watershed
Step 3
Driving function
Clearly,
Choose
Case 1 applies.
Hence
Case 2
Condition
If
where
then
Interpretation
The recursive work and the driving function are balanced.
Every level of the recursion tree contributes approximately the same cost.
Since there are levels, one extra factor appears.
Example 1 (Merge Sort)
Step 1
Step 2
Watershed
Step 3
Driving function
Exactly equal.
Therefore
Case 2.
Result
This is the Merge Sort analysis
Example 2
Watershed
Driving function
Therefore
Case 2
Answer
Case 3
Condition
If
and
for some
then
Regularity Condition
Case 3 requires one additional condition:
This ensures that the driving function decreases sufficiently as the recursion proceeds.
Note that this condition is satisfied by most polynomially bounded functions encountered in algorithm analysis.
Example
Here,
Watershed
Driving function
which is polynomially larger.
Regularity condition:
Hence Case 3 applies.
Final answer:
Summary of the Three Cases
| Case | Comparison | Result |
|---|---|---|
| Case1 | is polynomially smaller than the watershed function | |
| Case2 | ||
| Case3 |
Comments
Post a Comment