The running time of a simple loop-based algorithm satisfies T(n)=T(n−1)+nT(n) = T(n-1) + nT(n)=T(n−1)+n for n≥2n \ge 2n≥2, with T(1)=1T(1) = 1T(1)=1. A student finds a closed form by repeatedly substituting the recurrence into itself, which is called unrolling or iteration. Put the student's steps in the order they must be carried out.
1.
Evaluate the sum as T(n)=n(n+1)2T(n) = \dfrac{n(n+1)}{2}T(n)=2n(n+1).
2.
Substitute the recurrence for T(n−1)T(n-1)T(n−1) to get T(n)=T(n−2)+(n−1)+nT(n) = T(n-2) + (n-1) + nT(n)=T(n−2)+(n−1)+n.
3.
Choose k=n−1k = n-1k=n−1 so that the remaining term is the base case T(1)T(1)T(1).
4.
Prove the closed form for every n≥1n \ge 1n≥1 by induction.
5.
Repeat the substitution and spot the pattern T(n)=T(n−k)+(n−k+1)+⋯+nT(n) = T(n-k) + (n-k+1) + \dots + nT(n)=T(n−k)+(n−k+1)+⋯+n.
6.
Replace T(1)T(1)T(1) with 111 to get T(n)=1+2+⋯+nT(n) = 1 + 2 + \dots + nT(n)=1+2+⋯+n.
Unlock full course notes by signing up
Fitting initial conditions to a closed form
A sequence satisfies an=an−1+6an−2a_n = a_{n-1} + 6a_{n-2}an=an−1+6an−2 for n≥2n \ge 2n≥2, with a0=3a_0 = 3a0=3 and a1=4a_1 = 4a1=4. Its closed form can be written as an=A⋅3n+B⋅(−2)na_n = A\cdot 3^n + B\cdot(-2)^nan=A⋅3n+B⋅(−2)n. Find the exact integer values of the constants AAA and BBB, and use the closed form to find the exact integer value of a5a_5a5.
Recurrence with a repeated characteristic root
A sequence satisfies an=4an−1−4an−2a_n = 4a_{n-1} - 4a_{n-2}an=4an−1−4an−2 for n≥2n \ge 2n≥2, with initial values a0=1a_0 = 1a0=1 and a1=6a_1 = 6a1=6. Find a closed form for ana_nan and use it to find a10a_{10}a10. Give your answer as an exact integer.
Modelling a counting problem with a recurrence
Let ana_nan be the number of binary strings of length nnn that contain no two consecutive 1s. For example, 0110 is not allowed, but 0101 is. Which recurrence, together with its initial values, correctly describes ana_nan?
Second-order recurrence with a constant forcing term
A sequence satisfies an=5an−1−6an−2+4a_n = 5a_{n-1} - 6a_{n-2} + 4an=5an−1−6an−2+4 for n≥2n \ge 2n≥2, with a0=4a_0 = 4a0=4 and a1=9a_1 = 9a1=9.
Its general solution has the form an=A⋅r1 n+B⋅r2 n+pa_n = A \cdot r_1^{\,n} + B \cdot r_2^{\,n} + pan=A⋅r1n+B⋅r2n+p. Here r1<r2r_1 < r_2r1<r2 are the roots of the characteristic equation of the associated homogeneous recurrence, and ppp is a constant particular solution.
Give each of the following as an exact integer: