Master Theorem
In questa pagina 5
The Master Theorem (MT) gives the order of growth of an important class of recurrences without solving them exactly. It is a restricted consequence of the general formulaThe recurrence tree has the shape of the call tree of the worst instance and T(n) is the sum of the works of its nodes. For the family T(n) = s(n) T(f(n)) + w(n) with base T0 for n <= n0, counting nodes per level with the iterates of f and the level f*(n,n0) gives the closed formula T(n) = sum over levels of [product of s] w + [product of s] T0, proved by induction and applied to merge sort, Hanoi and square-root recurrences.Recurrence Relations - Recursion Tree and General Formula →.
Statement
Let , an integer and non-decreasing. For , This is the general formula with , , . The threshold function is .
Theorem (Master Theorem).
- Case 1: if then .
- Case 2: if then .
- Case 3: if and (regularity) , then .
The MT is not exhaustive. Example: , , : threshold , and is larger, but for every , so and Case 3 fails. The gap from the threshold must be a polynomial factor , not a logarithmic one.
Proof
Preliminary. For positive integer-domain functions, and can be taken valid for all : if for , take ; for use the minimum.
Starting point. The general formula with , nodes at level and gives The last term is since . Study the sum.
Case 1. . With : So the sum is and (if , only ). The leaves dominate.
Case 2. . The term does not depend on : every level costs the same, there are levels, so the sum is and so is .
Case 3. Regularity implies (induction on : ). Then The threshold term is dominated by , so ; and , so .
Meaning for design. Case 1: the leaves dominate (reduce the number of subinstances, as Strassen does). Case 3: the root work dominates (reduce it). Case 2: balanced, every level costs the same (a different substructure is usually needed to improve).
Extended version and use
The three cases hold identically for and for , otherwise, for arbitrary (proof omitted: stopping at replaces constant-depth subtrees by a constant). Hence, when applying the MT only, one writes with no rounding; elsewhere this notation is meaningless.
How to apply. (1) read , , ; (2) threshold ; (3) compare exponents if : Case 1, Case 2, Case 3; (4) in Case 3 find with .
Regularity is automatic for polynomials. If with : so .
Applications
| Recurrence | , | threshold | comparison | case | result |
|---|---|---|---|---|---|
| (MAX) | 2, 2 | , | 1 | ||
| (merge sort) | 2, 2 | 2 | |||
| (binary search) | 1, 2 | 2 | |||
| 3, 2 | 1 | ||||
| (Strassen type) | 7, 2 | 1 | |||
| 4, 2 | 2 | ||||
| 1, 2 | , | 3 | |||
| 3, 4 | , | 3 | |||
| 8, 2 | 1 |
Regularity for the Case 3 rows: : ; : .
Misuse of the MT
Take , . Threshold ; , so Cases 1 and 2 fail. Case 3 would need , false since : the MT does not apply. Applying Case 3 anyway would give , which is wrong. Unfolding with the general formula (): using and Gauss' sum. Check: , .
Versione ripasso
- Recurrence: , , integer, non-decreasing, ; threshold (from , see Recurrence Relations - Recursion Tree and General FormulaThe recurrence tree has the shape of the call tree of the worst instance and T(n) is the sum of the works of its nodes. For the family T(n) = s(n) T(f(n)) + w(n) with base T0 for n <= n0, counting nodes per level with the iterates of f and the level f*(n,n0) gives the closed formula T(n) = sum over levels of [product of s] w + [product of s] T0, proved by induction and applied to merge sort, Hanoi and square-root recurrences.Recurrence Relations - Recursion Tree and General Formula →).
- Case 1: (leaves dominate; sum ). Case 2: (each level costs ). Case 3: and regularity , (regularity gives , sum ; ).
- Proof tools: / extended to all via , of the initial ratios; . If , Case 1 gives only .
- Extension: valid with , , arbitrary ; write only for the MT.
- Not exhaustive: fits no case (gap must be a power ). For regularity holds with .
- How to apply: read ; threshold ; compare exponents for : Case 1, Case 2, Case 3; Case 3: find .
- Examples: ; ; ; ; ; ; ; (); ().
- Meaning: Case 1 leaves dominate (cut subinstances, e.g. Strassen); Case 3 root dominates; Case 2 all levels equal (seek another substructure).
- Misuse: : no case applies; unfolding gives (Case 3 would wrongly give ).
- Common mistakes: Case 3 with a merely logarithmic gap; skipping regularity; confused with ; MT with subinstances of different sizes (use the general formula or an upper bound with equal sizes); rounding-free notation outside the MT.
Teoria collegata
- Fast Exponentiation by Repeated Squaring
- Fast Fourier Transform
- Matrix Multiplication - Iterative and Recursive Block Product
- Parametric Induction
- Recurrence Relations - Recursion Tree and General Formula
- Strassen's Algorithm
- Structured Block Matrices - Reducing Recursive Calls
- Supercirculant and Circulant Matrices