Analysing time and space
State the input size, basic operation and input class before simplifying. A worst-case function and an expected function answer different questions. General recurrence algebra belongs to Engineering Mathematics; this chapter applies it to algorithm costs.
2.1 Asymptotic bounds and growth
Past papers · CS 2014–2026 (23 papers): 7 questions, 8 marks
Let be eventually nonnegative, with for sufficiently large integer . Constants in bounds cannot depend on .
For eventually nonnegative functions, . are transitive; only is symmetric, while is equivalent to . Big O does not mean worst case: it can upper-bound any specified cost function.
2.2 Loops and exact work
Past papers · CS 2014–2026 (23 papers): 4 questions, 8 marks
Nested loops are summed over the actual inner range; adjacent loops are added. If a variable persists between outer iterations, do not restart its count mentally. The number returned by a function need not equal its running time.
| Shape of work | Tight order | Reason |
|---|---|---|
| Inner range through , outer through | Triangular sum | |
| Inner increment , inner range at most , outer through | Harmonic sum | |
| Work then then | Geometric sum | |
| Work on each halving iteration | Same work at each level | |
| Unit work over | Exactly triples |
2.3 Recursion trees and the master theorem
Past papers · CS 2014–2026 (23 papers): 4 questions, 6 marks
A call creates subproblems and performs local work. For equal reductions, count the nodes and the work per node on each level; include the leaves. Use a constant-size base case with positive constant cost.
For the critical case with negative , sum the levels: gives , gives , and gives . Stop at an input size above so logarithmic denominators are defined. These extensions follow from a power sum over the remaining levels; do not use the polynomial-gap cases when only a logarithmic gap exists.
2.4 Recurrences beyond equal splits
Past papers · CS 2014–2026 (23 papers): 6 questions, 9 marks
Choose a new variable when the input shrinks by a root. Normalize by an exponential or by when it cancels the multiplier. For coupled recurrences, solve the inner cost first and substitute its order into the outer one.
For with fixed and , work shrinks geometrically across levels and . If the fractions sum to , both bounded away from zero, the result is . The ordinary master theorem does not apply directly to unequal subproblem sizes.
For repeated th roots with a fixed threshold and fixed , the number of reductions from is . Include the base call in total calls. If parameters vary with , retain their dependence instead of replacing this by .
2.5 Peak storage and runtime scaling
Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks
Time adds all executed subcalls. Stack space measures only simultaneously live calls. Sequential recursive children do not occupy their entire recursion trees at once. Include local arrays retained by ancestor calls.
A balanced recursion with two sequential children and constant-size frames has logarithmic stack depth even if there are linearly many calls. If each active level retains an array proportional to its subproblem size, the path sum is storage. Naive slicing may copy data; do not charge only the stack in that implementation.
Last-minute recall
- Specify worst, best or expected cost before writing a bound.
- Constants in asymptotic definitions are independent of input size.
- Sum dependent loop lengths; do not multiply their maxima blindly.
- Count local work and leaf work in recursion trees.
- Master-theorem case 3 needs regularity.
- Logarithmic gaps are not polynomial gaps.
- Root recurrences need a threshold or rounding convention.
- Peak stack depth and total call count are different quantities.