★ Solving recurrences [00C6]
- March 19, 2026
In many situations, it is easy to write down a recurrence relation, but what we really want is a closed form. How can we figure out a closed form for a given recurrence? There are many techniques, but the simplest is to “unfold” the recurrence and look for a pattern.
Example Odd numbers, again [00C7]
- March 19, 2026
Let’s start by looking at a recurrence for the odd numbers: \begin {align*} g_0 &= 1 \\ g_n &= g_{n-1} + 2 & (n \geq 1) \end {align*}
We can start with g_n and keep unfolding it via the recurrence. For example, after unfolding to g_{n-1} + 2, the recurrence tells us that g_{n-1} = g_{n-2} + 2, so we can unfold again, and so on:
\begin {align*} g_n &= g_{n-1} + 2 \\ &= (g_{n-2} + 2) + 2 \\ &= ((g_{n-3} + 2) + 2) + 2 \\ &= \dots \end {align*}
We see a pattern: g_{n-k} is going to be followed by adding k copies of 2. So in general, we have g_n = g_{n-k} + 2k. Since we know the value of g_0, substituting k = n is helpful: g_n = g_{n-n} + 2n = g_0 + 2n = 1 + 2n. So we have derived the closed form g_n = 2n + 1 which is what we knew it should be.
Example [00C8]
- March 19, 2026
As another example, consider the recurrence \begin {align*} p_0 &= 0 \\ p_n &= 2p_{n-1} + 1 \end {align*} We have seen this recurrence before, and found a closed form just by looking at terms of the sequence and noticing a pattern. But we can derive the closed form more directly by unfolding: \begin {align*} p_n &= 2p_{n-1} + 1 \\ &= 2(2p_{n-2} + 1) + 1 \\ &= 2^2 p_{n-2} + 2 + 1 \\ &= 2^2 (2p_{n-3} + 1) + 2 + 1 \\ &= 2^3 p_{n-3} + 2^2 + 2 + 1 \\ &= \dots \\ &= 2^k p_{n-k} + 2^{k-1} + 2^{k-2} + \dots + 2 + 1 \\ &= 2^k p_{n-k} + 2^k - 1 \end {align*} The last step follows because 2^{k-1} + 2^{k-2} + \dots + 1 is the sum of a geometric sequence with ratio r = 2. When k = n, this becomes p_n = 2^n p_{n-n} + 2^n - 1 = 2^n - 1 since p_0 = 0.
Example [00C9]
- March 19, 2026
As another example, consider \begin {align*} q_0 &= 1 \\ q_n &= 3q_{n-1} + 2 \end {align*} The first few terms of this sequence are 1, 5, 17, 53, 161, \dots Unfolding: \begin {align*} q_n &= 3q_{n-1} + 2 \\ &= 3(3q_{n-2} + 2) + 2 \\ &= 3^2 q_{n-2} + 3\cdot 2 + 2 \\ &= 3^2 (3q_{n-3} + 2) + 3\cdot 2 + 2 \\ &= 3^3 q_{n-3} + 3^2 \cdot 2 + 3\cdot 2 + 2 \\ &= \dots \\ &= 3^k q_{n-k} + 3^{k-1} \cdot 2 + 3^{k-2} \cdot 2 + \dots + 2 \\ &= 3^k q_{n-k} + 2 (3^{k-1} + 3^{k-2} + \dots + 1) \\ &= 3^k q_{n-k} + 2 \frac {3^k - 1}{2} \\ &= 3^k q_{n-k} + 3^k - 1 \\ \end {align*} When k = n, we obtain q_n = 3^n q_0 + 3^k - 1 = 2 \cdot 3^n - 1. We can check that this is correct by (1) computing a few terms of the sequence and checking that our closed form generates the same terms, and/or (2) substituting our closed form into the recurrence to make sure it checks out.