Algorithms · Recurrence Relations and the Master Theorem
Forming Recurrence Equations from Recursive Functions
Overview
A recursive function calls itself on a smaller input, so its running time cannot be found by counting loop iterations. Instead, the time is expressed as a recurrence equation, which is then solved to obtain the complexity.
Key concepts
- Recursive function: a function that calls itself, typically on a smaller input such as (in general, on a reduced size of the input).
- Recurrence equation (recursive equation): the equation that expresses the time cost of a recursive function in terms of its cost on smaller inputs.
It is needed because a recursive function has nothing to "count" directly, so its analysis is very different from that of an iterative function. - : the time taken to solve the problem on an input of size .
- Scaling relation: if takes time , then a call takes time — the same function symbol with the argument scaled.
- Constant work: the base checks/comparisons (e.g. the
ifcondition) and the combining work (e.g. adding/summing the results) each cost a constant, written as or as 1.
How it works
- Let the time taken to solve the problem on an input of size be .
- Break the total time into the parts actually spent inside one call:
- constant time for the base checks/comparisons — e.g. the
ifcondition — call it some constant (or 1); - time for each recursive call: a call takes ;
- constant time for the combining work — e.g. the addition/summing up of the results.
- constant time for the base checks/comparisons — e.g. the
- Add all parts together. For a function that makes two calls each on input : constant time for the
ifcondition + constant time for the addition + 2 calls each costing . - Write this as the recurrence, then solve the recurrence (several methods exist).
Formulas
- = time taken to solve the problem of size .
- (or 1) = constant time for the
ifcondition and for the addition/combining step. - where is the cost of the two recursive calls and is the constant work (if condition + addition) inside the call.
Worked examples
Forming the recurrence for a function that performs an if comparison (constant time), calls twice, and adds/sums the two results (constant time):
- Time for is .
ifcondition costs a constant.- First call costs ; second call costs — i.e. in total.
- The addition of the results costs a constant.
- Total: constant + + constant, written as (the constants are collected into one constant term).

Revision summary
- A function calling itself is recursion; its cost is expressed as a recurrence, not by counting loop iterations.
- Always define = time for input size first, then split the time into: constant work inside the call + (number of calls) × + constant combining work.
- If costs , then costs — substitute the scaled argument into the same .
- Constants can be written as or as 1; it does not matter for the recurrence.
- After forming the recurrence, the next task is to solve it (several methods exist).
Previous-year exam insights
- Master Theorem: for T(n) = aT(n/b) + f(n) with a ≥ 1, b > 1, compare f(n) with ;
if − ε)) then T(n) = ;
if f(n) = then T(n) = ;
if f(n) = Ω() and the regularity condition a·f(n/b) ≤ c·f(n) holds for some c < 1, then T(n) = .
Asked inGATE 2021GATE 2026 - For recurrences with unequal subproblem sizes such as T(n) = T(αn) + T(βn) + f(n) with f(n) = : if α + β < 1 the total work forms a geometrically decreasing series, so T(n) = ;
if α + β = 1 each level costs and T(n) = .
Asked inGATE 2021 - For with a > 1 (and T(b) = 1), repeatedly taking roots gives T(n) = , i.e. the number of times a logarithm must be applied to reduce n to a constant.
Asked inGATE 2020GATE 2017 - Linear recurrences with constant coefficients (e.g. T(n) = c1·T(n−1) + c2·T(n−2)) are solved by the characteristic equation;
the dominant root r gives T(n) = , with a factor of n if the root is repeated.
Asked inGATE 2024 - For T(n) = aT(n−1) + f(n) with a > 1, the homogeneous part dominates: T(n) = , and for a polynomial f(n) the sum converges, so T(n) = (e.g. T(n) = 2T(n−1) + n is ).
Asked inGATE 2025 - A recurrence of the form T(n) = T(n−1) + c (or T(n) = 2T(n/2) + c) solves to , so different-looking recurrences can have the same asymptotic complexity;
always solve before comparing.
Asked inGATE 2026