optional · CSS study notes
Recurrence Relations
CSS Computer Science (Optional) — Paper-I, Section-B, Topic IV. Companion page to Recursion — that page introduces recursion itself and works the Substitution Method on two examples. This page catalogs every method for solving a recurrence relation (Substitution, Recursion Tree, Master Theorem, Characteristic Equation) side by side, works the two board-example recurrences in full, and closes with the most frequently tested question pattern.
What Is a Recurrence Relation?
- A recurrence relation defines a function's value at n in terms of its own value(s) at smaller input(s) — , , , etc. — together with one or more base case(s) that stop the chain.
- General shape:
- Why it matters for CSS/FPSC: a recursive algorithm's running time can only naturally be expressed as a recurrence — you cannot read its Big-O off the code directly the way you can for loops. Solving the recurrence is the step that converts "the code calls itself" into an actual O() answer.
- Solving a recurrence means finding its closed-form solution — an explicit formula for with no on the right-hand side — which is then simplified into a Big-O / Θ class.
Exam angle: examiners phrase this two ways — "solve the recurrence T(n) = ... using the substitution method" (they name the method) or "find the time complexity of Algorithm X" and give you the code (you must first write the recurrence yourself, then solve it). Practice recognizing code patterns as recurrences — see the Code-Pattern Cookbook on the Algorithms Analysis (2016) page.
Two Families of Recurrences
| Family | Shape | Argument shrinks by | Typical source | Typical answer |
|---|---|---|---|---|
| Subtractive (linear recursion) | Subtraction: n-1, n-2, ... | Factorial, linear recursive search, a loop written recursively | Polynomial or worse — , , | |
| Divide-and-conquer | Division: n/2, n/3, ... | Binary Search, Merge Sort, Quick Sort | Usually fast — , | |
| Multi-term linear homogeneous | Multiple smaller terms, no division | Naive recursive Fibonacci, exhaustive branching recursion | Exponential — , |
Exam angle: identify which family you have before picking a method. This one classification move tells you which method even applies (Master Theorem only works on the divide-and-conquer shape) and roughly what answer to expect, so you can sanity-check your final algebra against it.
Method 1 — Substitution (Iteration) Method
Expand the recurrence into itself repeatedly until a pattern in the substitution count k emerges, then find k from the base case and substitute back. Full 4-step method is on the Recursion page; summarized here:
- Write the recurrence, expand the recursive term using the recurrence's own definition.
- Spot the pattern after 2–3 substitutions, in terms of k.
- Find k by setting the recursive argument equal to the base case.
- Substitute k back, plug in the base value, simplify to a closed form.
Worked Example A — Subtractive: Factorial (summary)
Expanding: . Base hits at , giving
so . Full step-by-step derivation: see Recursion.
Worked Example B — Subtractive with extra term: T(n) = T(n-1) + log n
Step 1 — write the equation and substitute repeatedly:
Step 2 — spot the pattern after k substitutions:
| Substitutions (k) | Expression |
|---|---|
| 1 | |
| 2 | |
| 3 |
General form:
Step 3 — find k using the base case: recursion stops when the argument hits n = 1:
Step 4 — substitute k = n-1 back in:
Since :
Step 5 — classify with Big-O using Stirling's approximation (, a standard result worth memorizing on its own — it's how factorial's log connects back to the divide-and-conquer complexity class):
Key reasoning point: this recurrence sits between the two families above — it subtracts like the factorial recurrence (k = n-1 substitutions, not log n of them), but because the added term shrinks in magnitude each step (unlike factorial's multiplied growing term), the sum of logs collapses to rather than blowing up to itself. Contrast all three: , , — same subtractive shrinkage, three very different answers, purely from what's added/multiplied at each step.
Exam angle: FPSC sometimes disguises this exact pattern as "find the number of comparisons if a function does O(log n) work at every one of its n recursive subtractive calls" — recognize it as and the substitution method above applies directly.
Worked Example C — Divide-and-conquer: Binary Search (summary)
, — substituting k times gives ; base hits at , giving
Full 9-step derivation (an actual 2016 FPSC Q5(b) past question): see Recursion.
Method 2 — Recursion Tree Method
Draw the recursion as a tree: each node is the non-recursive work done at that call (excluding its children); sum the work level by level, then sum across all levels.
- Draw the root = the non-recursive cost of the top-level call, .
- Expand each child the same way, one level per recursive call.
- Find the total cost per level (often constant across levels) and the tree's depth (levels until reaching the base case) or number of leaves.
- Sum level-costs × number-of-levels (or leaf-cost × number-of-leaves, plus internal levels) to get total .
Worked Example — Merge Sort: T(n) = 2T(n/2) + cn
| Level | Number of nodes | Size per node | Cost per node | Total cost at this level |
|---|---|---|---|---|
| 0 (root) | 1 | n | ||
| 1 | 2 | n/2 | ||
| 2 | 4 | n/4 | ||
| ... | ... | ... | ... | |
| (leaves) | n | 1 |
Every level costs , independent of the level — a direct consequence of the work splitting into exactly half-sized pieces while doubling in count each time. The tree has levels (root at level 0, leaves at level , since the array halves from n down to 1).
Total:
— matches the well-known Merge Sort complexity, derived here from first principles rather than quoted.
Exam angle: the recursion tree method is FPSC's preferred way to ask you to derive for Merge Sort rather than just state it — draw the tree, label each level's total cost, and explicitly state that it's constant () across all levels; that constancy is the key insight examiners look for.
Method 3 — Master Theorem
For recurrences of the exact divide-and-conquer shape ( subproblems, each of size , , plus extra work), compare against :
| Case | Condition | Result | Intuition |
|---|---|---|---|
| 1 | for some | The recursive splitting dominates — leaf work outweighs the combine step | |
| 2 | Splitting and combine work are balanced at every level (Merge Sort's case) | ||
| 3 | , plus the regularity condition for some | The combine step dominates — top-level work outweighs the recursion |
Applying it
| Recurrence | a, b, f(n) | Case | Result | |
|---|---|---|---|---|
| Merge Sort: | 2 — | ✓ matches the recursion-tree derivation above | ||
| Binary Search: | 2 — | ✓ matches Example C above | ||
| 1 — | ||||
| 3 — , regularity holds |
When the Master Theorem Does NOT Apply
- Unequal-sized subproblems, e.g. — needs a recursion tree instead (subproblem sizes differ, so there's no single b).
- f(n) not polynomially comparable to , e.g. — f(n) is asymptotically between the cases (falls in the gap), so none of the 3 cases fit — needs the more general Akra–Bazzi method or a recursion tree.
- a not constant / a < 1, or subtractive recurrences like (this isn't of the shape at all — use substitution instead, as in Example B).
Exam angle: a favorite FPSC MCQ trap is giving a recurrence resembling and asking "which Master Theorem case applies?" — correct answer: none; Master Theorem is inapplicable here. Always check the polynomial-gap condition, not just "is f(n) bigger or smaller."
For the full deep-dive — recursion-tree intuition for why the theorem works, the generalized Case 2 (with an extra log factor), more worked examples per case, the regularity-condition check done explicitly, a decision flowchart, and dedicated CSS/FPSC practice questions — see the standalone Master Theorem page.
Method 4 — Characteristic Equation (Linear Homogeneous Recurrences)
For a recurrence that's a linear combination of previous terms with constant coefficients and no extra f(n) — the classic case being Fibonacci — solve algebraically instead of expanding:
Worked Example — Fibonacci: T(n) = T(n-1) + T(n-2)
- Assume a solution of the form .
- Substitute and divide out the smallest power:
(the characteristic equation).
- Solve the quadratic:
giving two roots: (the golden ratio) and .
- General solution: , with A, B fixed by the base cases ().
- Since , the term shrinks to 0 as n grows, so the dominant term is :
— commonly loosely quoted/bounded as since , which is the number normally expected in an FPSC answer unless the question specifically asks for the tight golden-ratio bound.
Cross-check against the recursion-tree/counting view: the naive recursive Fibonacci call tree is a binary tree of depth n where each node spawns 2 children — a direct match to the upper bound; the characteristic-equation method gives the tighter because not every branch of that tree actually runs to full depth. Full pseudocode + call-count reasoning: see Recursion.
Exam angle: FPSC rarely asks you to derive the characteristic equation from scratch, but frequently asks "why is naive recursive Fibonacci exponential?" — the expected answer combines both views: (a) the call tree branches in 2 directions at every non-base call, and (b) many identical subproblems (e.g. Fibonacci(n-3)) are recomputed across different branches instead of cached — the fix being memoization/DP, bringing it down to O(n).
Quick Reference — Common Recurrences → Answers
| Recurrence | Best method | Closed-form / complexity |
|---|---|---|
| Substitution | ||
| Substitution | ||
| Substitution | — Example B above | |
| Substitution | — Example A above | |
| Substitution or Master Thm | — Example C above | |
| Recursion Tree or Master Thm | — Merge Sort | |
| Master Theorem | ||
| Characteristic Equation | , bounded — Fibonacci |
📌 Most Frequently Tested Pattern — Recurrence Relations (CSS/FPSC)
Across the Section-B papers reviewed for this workspace, recurrence-relation questions consistently follow one of two verified formats:
- "Solve this recurrence using the substitution/iteration method" with either a subtraction-based (factorial-style) or division-based (Binary Search-style) recurrence given explicitly — see the confirmed real past question below.
- A complexity-classification MCQ embedded inside a broader Recursion/Algorithms Analysis MCQ set (base case, what prevents infinite recursion, which notation is used, etc.) — see the MCQ examples on the Recursion and 🔥 Most Repeated — Algorithms & Data Structures pages.
✅ Verified Past Question
2016, Paper I, Q5(b) (6 marks) — Find the time complexity of Binary Search by resolving the recurrence (), (), using the iterative substitution method.
Full 9-step solution: worked as Example C above, and in full detail on the Recursion page. Answer: .
📝 Practice Questions (in the same tested pattern — work these using the methods above)
These are not sourced from a specific verified past paper — they're modeled on the confirmed pattern above, for drilling all four methods.
- Substitution, subtractive-with-term (Example B pattern): Solve for , , using the substitution method. (Answer: — same subtractive shrinkage as Example B, but a linearly-growing added term instead of a logarithmically-growing one.)
- Recursion tree: Draw the recursion tree for and find . (This is Master Theorem Case 1: , dominates → .)
- Master Theorem classification MCQ: Which case of the Master Theorem applies to ? (; → Case 1 → .)
- Conceptual/short-answer: Explain why the Master Theorem cannot be applied directly to . (Unequal subproblem sizes — no single b — use a recursion tree; the tree remains unbalanced but still resolves to since every level still totals n.)
- Characteristic equation: Derive the closed-form growth rate of and state why it is exponential rather than polynomial. (See Method 4 — .)
- "Which method would you use" (identification MCQ): A recurrence of the form is best solved using: A) Master Theorem B) Characteristic equation C) Recursion tree only D) Cannot be solved. (Answer: A — it's exactly the shape the theorem targets, though a recursion tree would confirm the same answer.)
Exam angle — the single highest-leverage move: before writing any algebra, classify the recurrence into one of the three families in the table near the top of this page. That one step tells the examiner (and you) which method you're about to apply and why — FPSC awards method-selection reasoning marks separately from the final closed-form answer.
📜 Past-Paper Questions & MCQs (CSS 2016–2026)
2016 · Paper-I · Q5(b) · 6 marks
Q. Find the time complexity of binary search by solving the recurrence T(1) = 2 and T(n) = 4 + T(n/2) for n > 1, by iterative substitution.
Ans.
- T(n) = 4 + T(n/2)
- = 4 + 4 + T(n/4) = 2·4 + T(n/2²)
- = 3·4 + T(n/2³)
- After k steps: T(n) = 4k + T(n/2ᵏ).
- Stop when n/2ᵏ = 1, that is k = log₂ n.
- T(n) = 4 log₂ n + T(1) = 4 log₂ n + 2.
- Therefore T(n) = O(log n).