Recurrence Relations
A recurrence relation defines each term of a sequence from previous terms. It is a natural language for processes that evolve step by step: population models, recursive algorithms, dynamic programming, and counting strings with constraints.
Solving a recurrence means replacing the step-by-step definition with a closed form or at least a sharp growth estimate. Modeling and solving are different skills. The modeling step explains why the terms satisfy the recurrence; the solving step uses iteration, characteristic equations, generating functions, recursion trees, or asymptotic methods.
Definitions
A recurrence relation for a sequence is an equation that expresses in terms of earlier terms. Initial conditions specify enough starting values to determine the sequence uniquely.
A recurrence is linear homogeneous with constant coefficients if it has the form
It is nonhomogeneous if an extra term depending on appears:
A divide-and-conquer recurrence often has the form
where subproblems of size are solved and additional work is done to split or combine.
A closed form expresses directly in terms of without referring to earlier terms. An asymptotic solution describes growth, such as , even if no exact closed form is needed.
Key results
For the first-order geometric recurrence
iteration gives .
For the arithmetic recurrence
iteration gives .
For a second-order linear homogeneous recurrence
try . This yields the characteristic equation
If it has distinct roots , then
for constants determined by the initial conditions. If there is a repeated root , then
For merge sort,
solves to because each recursion level costs and there are levels. More generally, recursion trees expose whether cost is concentrated near the root, evenly across levels, or near the leaves.
The master theorem for many recurrences compares with . It is powerful but not universal; it requires regularity conditions and does not handle every recurrence.
Visual
| Recurrence | Method | Result pattern |
|---|---|---|
| iteration | exponential or constant | |
| telescoping | linear | |
| characteristic equation | Fibonacci-type | |
| recursion tree | ||
| summation | accumulated forcing term |
Worked example 1: Solve a linear recurrence
Problem. Solve
Method.
- Try :
- Divide by for :
- The characteristic equation is
- Distinct roots give
- Use :
- Use :
- Subtract twice the first equation from the second:
Then .
Checked answer. The solution is
Checking: , , and .
Worked example 2: Count bit strings with no consecutive zeros
Problem. Let be the number of bit strings of length with no consecutive zeros. Find a recurrence and compute .
Method.
- Separate valid strings by their ending.
- If a valid string of length ends in , then the first bits can be any valid string of length . This contributes strings.
- If it ends in , then the previous bit must be , so the string ends in . The first bits can be any valid string of length . This contributes strings.
- Therefore
- Initial values:
for the empty string, and
for strings and .
- Compute:
Checked answer. There are length- bit strings with no consecutive zeros. A brute-force listing confirms this count.
Code
def no_consecutive_zeros(n):
if n == 0:
return 1
if n == 1:
return 2
prev2, prev1 = 1, 2
for _ in range(2, n + 1):
prev2, prev1 = prev1, prev1 + prev2
return prev1
def solve_second_order(a0, a1, c1, c2, nmax):
seq = [a0, a1]
for n in range(2, nmax + 1):
seq.append(c1 * seq[n - 1] + c2 * seq[n - 2])
return seq
print([no_consecutive_zeros(n) for n in range(8)])
print(solve_second_order(2, 5, 5, -6, 8))
The second function numerically checks the recurrence from the first worked example, producing values of .
Common pitfalls
- Giving a recurrence without enough initial conditions. A second-order recurrence usually needs two starting values.
- Solving a recurrence but not checking the initial conditions.
- Treating the characteristic-equation method as valid for non-linear recurrences.
- Forgetting the empty object in counting recurrences. Often is the clean base case.
- Miscounting ending cases that overlap. In the bit-string example, "ends in " and "ends in " are disjoint and exhaustive.
- Applying the master theorem outside its hypotheses.
A good recurrence solution has three separate checks: the model, the algebra, and the initial conditions. The model explains why the recurrence counts the intended objects or measures the intended running time. The algebra solves that recurrence. The initial conditions pin down the constants. A closed form that satisfies the recurrence but misses or is not the solution to the original problem.
When deriving counting recurrences, make cases disjoint by using the end, beginning, or first special position. For bit strings with no consecutive zeros, "ends in " and "ends in " work because they are disjoint and cover all valid strings. Cases such as "has a somewhere" and "has a somewhere" overlap and cannot simply be added.
Characteristic equations apply to linear homogeneous recurrences with constant coefficients. They do not directly solve , , or . Those require other methods. Before using the characteristic equation, identify the recurrence type and verify that the coefficients are constant and the recurrence is linear in previous terms.
For nonhomogeneous recurrences, solve the homogeneous part and then find one particular solution. For example, has homogeneous solution and a constant particular solution , giving . Substituting back is the fastest way to check the guessed particular form.
For algorithmic recurrences, specify the input sizes covered. Many divide-and-conquer formulas are first solved for powers of two and then extended asymptotically. That is acceptable when stated, but exact formulas may differ for non-powers of two because floors and ceilings change subproblem sizes.
Iteration is often the simplest first attempt. For , write and continue until a pattern appears. The pattern can then be proved by induction. This method is especially useful before introducing characteristic equations, because it keeps the meaning of each term visible.
For recurrences that count strings, draw the last few valid objects. If a recurrence predicts for no consecutive zeros, list . The list confirms both the count and the decomposition. If the list contains an object in two cases or misses an object, the recurrence needs adjustment.
For dynamic programming recurrences, identify the state carefully. A state should contain enough information to make the next decision without remembering the entire history. For example, counting strings with no consecutive zeros needs to know whether the previous bit was zero if building left to right. Choosing a state that is too small gives wrong transitions; choosing one that is too large makes the algorithm harder than necessary.
When a closed form is proposed, verify it in two places: the initial conditions and the recurrence. Checking only the first few terms can miss a formula that matches early values by coincidence. Checking only the recurrence can miss the constants. A complete verification substitutes the formula into the recurrence and separately checks all required initial values.
In algorithm analysis, decide whether the recurrence is exact or asymptotic. Writing may ignore floor, ceiling, and base-case details. That is often fine for bounds, but exact operation counts require a precise domain such as powers of two and a precise base case.
When a recurrence is solved by a table of values, look for both additive and multiplicative patterns. First differences may reveal an arithmetic component; ratios may reveal geometric growth. These observations are not proofs, but they suggest which formal method to try next: telescoping, characteristic equations, or generating functions.
Connections
- Induction and recursion gives the proof method for recursive definitions.
- Functions, sequences, and sums introduces sequences and summation notation.
- Generating functions solves recurrences by turning sequences into power series.
- Algorithms and complexity uses recurrences to analyze divide-and-conquer algorithms.
- Counting principles supplies combinatorial decompositions that lead to recurrences.