Example. [00C9]

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.