Course: Advanced Data Structures and Algorithms
-
General Form:
$T(n) = a T(n/b) + n^c$ -
Parameters:
-
$a$ : Number of subproblems (copies). -
$n/b$ : Size of each subproblem. -
$n^c$ : Combining/Splitting cost (work done at the current level).
-
- Goal: Find a closed-form solution to avoid manual expansion.
-
Substitution: Assume
$n = b^k$ . -
Chain of Expansion:
$T(b^k) = a T(b^{k-1}) + (b^k)^c$ $T(b^k) = a^2 T(b^{k-2}) + a(b^{k-1})^c + (b^k)^c$ $T(b^k) = a^k T(1) + \sum_{i=0}^{k-1} a^i (b^{k-i})^c$
-
Resulting Geometric Progression:
- The sum involves a ratio
$x = b^c / a$ . - The behavior depends on whether
$x$ is$< 1$ ,$= 1$ , or$> 1$ .
- The sum involves a ratio
-
Case 1:
$b^c < a$ (Subproblem work dominates)$T(n) = \Theta(n^{\log_b a})$ - Example: Karatsuba (
$3 > 2^1$ ) yields$n^{\log_2 3} \approx n^{1.59}$ .
-
Case 2:
$b^c = a$ (Work is equal across levels)$T(n) = \Theta(n^c \log n)$ - Example: Merge Sort (
$2 = 2^1$ ) yields$n \log n$ .
-
Case 3:
$b^c > a$ (Root combining cost dominates)$T(n) = \Theta(n^c)$ - Example: A hypothetical algorithm where the merge cost is so high (
$n^2$ ) that splitting doesn't save asymptotic time.
-
Nodes: Circular nodes represent recursive calls (
$T$ ); square nodes represent concrete work done ($n^c$ ). -
Levels: Level
$i$ has$a^i$ nodes, each doing$(n/b^i)^c$ work. - Total Work: The sum of work at each horizontal level.
-
Case Study:
$T(n) = 2T(n/2) + n \log n$ .- Since
$n \log n \neq n^c$ , Master Theorem doesn't apply directly. -
Manual Expansion:
$T(n) = n T(1) + n \sum \log(n/2^i)$ . -
Result:
$\Theta(n \log^2 n)$ .
- Since
-
Mathematical Sensitivity: Small changes in subproblems (reducing
$a$ from 4 to 3) or combining costs (reducing$c$ ) result in massive asymptotic performance gains ($n^2 \to n^{1.59}$ ).
- If an algorithm is slow, the Master Theorem identifies the exact bottleneck.
- Cluelessly tinkering with code is less effective than mathematically analyzing if one should focus on reducing the number of subproblems (
$a$ ) or the merging efficiency ($c$ ). - "Math works at a meta-level... it gives you a generalized view."
Key Terms Corrected:
- cross voiced -> Karatsuba's
- a copies ->
$a$ copies - B k ->
$b^k$ - D ->
$d$ (base case constant) - alpha ->
$\alpha$ (constant factor) - k times k plus 1 by 2 ->
$k(k+1)/2$