Time Complexity via Divide-and-Conquer Recurrences (Two Worked Examples)
This section teaches how to compute asymptotic running time for two recurrences—one “variable-size divide-and-conquer” and one “incremental” recurrence.
We will solve:
We’ll use a standard “recurrence tree / unfolding” strategy for (i) and summation (telescoping / series) for (ii).
type="tip" title="Pro Tip" content="When the subproblem size changes nonlinearly (like ), switch from Master Theorem to recurrence-tree/unrolling and track how many levels occur and what each level costs."
Key keywords you’ll use
- Recurrence
- Recurrence tree
- Unrolling
- Base case
(Next, we do the full derivations.)
Solve (i) T(n)=√n·T(√n)+n via recurrence-tree unrolling
- 1Step 1
Let and define , so .
- 2Step 2
At level , the recurrence contributes a factor of in front of the next . Since , we get .
- 3Step 3
At each level, the additive term contributes (because the '+n' in becomes '+(current subproblem size)' when unfolded).
- 4Step 4
Stop when (or any constant). Solve → → , hence .
- 5Step 5
Total cost is approximately Using Thus the level- term becomes .
- 6Step 6
Each level contributes , and there are levels, so
Result for (i)
Why this happens (intuition):
Unrolling produces about levels because each step takes a square root, so the exponent shrinks geometrically. Meanwhile, although the subproblem sizes shrink, the multiplicative factor from expands in exactly the right way so that the effective cost per level stays on the order of .
type="warning" title="Common Pitfall" content="Do NOT apply the standard Master Theorem directly here: the subproblem size is but the number of subproblems is effectively variable (the multiplier is , not a constant ). That’s why recurrence-tree accounting/unrolling is safer."
Solve (ii) T(n)=T(n-1)+1/n using telescoping unrolling
- 1Step 1
"For iterate:
- 2Step 2
"Let . Then
- 3Step 3
A standard fact is , so
Result for (ii)
Intuition:
You add each step. Summing from to yields the harmonic series, which grows logarithmically.
Asymptotic running time comparison
Two different recurrence styles yield distinct growth rates.
Learning roadmap for these recurrence types
Identify recurrence structure
Step ACheck whether coefficients/subproblem sizes are constant or variable (e.g., multiplier)."
Choose the right method
Step BUse unrolling/recurrence tree for variable divide-and-conquer; use telescoping/sums for linear recurrences."
Count levels and sum per level
Step CFor -style recurrences, levels are about ."
Convert sums to known series
Step DFor , use harmonic growth ."
FAQs and edge cases
Knowledge Check
For , the number of recurrence-tree levels is approximately:
Explore Related Topics
Complexity Analysis: Best Case, Worst Case, and Average Case
The material introduces best‑case, worst‑case, and average‑case complexity as three distinct functions describing an algorithm’s running time on inputs of size , explains how they are formally defined, and shows why worst‑case analysis is usually preferred.
- Best case: , the minimum time over all inputs of size .
- Worst case: , giving a guaranteed upper bound.
- Average case: , requiring an explicit input probability model.
- Linear search illustrates the three cases: best, worst, and average (expected comparisons).
- Worst‑case analysis is favored because it needs no probabilistic assumptions and ensures reliability for all inputs, especially in real‑time or safety‑critical systems.
Differentiating Divide & Conquer, Greedy Method, and Dynamic Programming
Mastering Recurrence Relations: The Substitution Method
The lesson shows how to solve the classic recurrence with the substitution method, using a recursion‑tree intuition to guess an bound and then proving it by induction.
- Each level of the recursion tree costs , and there are levels → total .
- Inductive hypothesis: for , which simplifies to in the induction step.
- The base case must start at (e.g., ) because is false.
- Substitution offers rigorous proof, while recursion trees give quick guesses; the Master Theorem confirms .