Skip to content

Recursion

Updated Β· Equations updated; Diagrams updated; Sections updated; Examples or practice updated; Explanations expanded What changed?
  1. β€” Equations updated; Diagrams updated; Sections updated; Examples or practice updated; Explanations expanded

Recursion uses earlier terms of a sequence to construct the next term. It appears in explicit recurrence problems on the AIME, USAMO, and USAJMO, as well as in counting and other combinatorics problems.

These notes are adapted in part from Jeffrey Chen’s Recursion in the AIME handout and the generating-functions section of the summations notes.

A recurrence relation expresses a term of a sequence in terms of earlier terms. For example,

an=3anβˆ’1a_n = 3a_{n-1}

means that every term is three times the previous one. If a1=1a_1=1, then

a2=3,a3=9,a4=27,a_2=3,\qquad a_3=9,\qquad a_4=27,

so the sequence begins

1,3,9,27,81,…1,3,9,27,81,\dots

Because the relation holds for every valid nn, we can repeatedly substitute backwards. For instance, if

an=3anβˆ’1andanβˆ’1=3anβˆ’2,a_n=3a_{n-1} \qquad\text{and}\qquad a_{n-1}=3a_{n-2},

then

an=9anβˆ’2.a_n=9a_{n-2}.

In contest math, we often do not need a closed form.

An explicit formula computes ana_n directly from nn. Repeatedly applying an=ranβˆ’1a_n=ra_{n-1} gives an=a0rna_n=a_0r^n when the indexing starts at zero. An arithmetic recurrence an=anβˆ’1+da_n=a_{n-1}+d similarly gives an=a0+nda_n=a_0+nd. Check the starting index: with a1a_1 instead, the exponents and increments use nβˆ’1n-1.

For an affine recurrence an+1=ran+ca_{n+1}=ra_n+c with rβ‰ 1r\ne1, find a fixed value L=rL+cL=rL+c. Subtracting it gives an+1βˆ’L=r(anβˆ’L)a_{n+1}-L=r(a_n-L), a geometric recurrence.

Example. A sequence satisfies a0=1a_0=1 and an+1=3an+4a_{n+1}=3a_n+4. Find ana_n.

The fixed value solves L=3L+4L=3L+4, so L=βˆ’2L=-2. Set bn=an+2b_n=a_n+2. Then bn+1=3bnb_{n+1}=3b_n and b0=3b_0=3, giving

an=bnβˆ’2=3n+1βˆ’2.a_n=b_n-2=3^{n+1}-2.

At n=0n=0 this gives one, and substitution reproduces the recurrence, verifying the formula.

For a homogeneous linear recurrence an=panβˆ’1+qanβˆ’2a_n=pa_{n-1}+qa_{n-2}, try a solution an=rna_n=r^n. This gives the characteristic equation r2βˆ’prβˆ’q=0r^2-pr-q=0. If its roots r1,r2r_1,r_2 are distinct, the general solution is Ar1n+Br2nA r_1^n+B r_2^n, with the constants determined by two initial values. Substitution verifies the recurrence, and the initial values determine every later term uniquely.

Example. Find the sequence with a0=0a_0=0, a1=1a_1=1, and an=5anβˆ’1βˆ’6anβˆ’2a_n=5a_{n-1}-6a_{n-2} for nβ‰₯2n\ge2.

The characteristic equation is (rβˆ’2)(rβˆ’3)=0(r-2)(r-3)=0. Write an=A2n+B3na_n=A2^n+B3^n. The initial values give A+B=0A+B=0 and 2A+3B=12A+3B=1, hence A=βˆ’1,B=1A=-1,B=1. Thus

an=3nβˆ’2n.a_n=3^n-2^n.

For a nonzero repeated characteristic root rr, use (A+Bn)rn(A+Bn)r^n instead. Nonhomogeneous recurrences need an additional particular solution; the fixed-value shift above is one simple example.

When only a remainder is requested, track residues rather than the entire sequence. For a first-order recurrence modulo mm, there are only mm states, so some state eventually repeats. A deterministic transition then repeats forever from that point. For a second-order recurrence, the state must include the pair of consecutive residues.

Example. Let a0=0a_0=0 and an+1=an2+1a_{n+1}=a_n^2+1. Find a100(mod5)a_{100}\pmod5.

The residues are 0,1,2,0,1,2,…0,1,2,0,1,2,\ldots. The return to the full state zero proves a period of three. Since 100≑1(mod3)100\equiv1\pmod3, the requested remainder is 11.


Recursion becomes especially useful when direct counting is messy but a β€œlast move” or β€œfinal case split” is easy to describe.

Example. Fred wants to climb a 1010-step staircase. He can climb either 11 or 22 steps at a time. In how many ways can he climb the staircase?

Solution. Instead of counting only the 1010-step case, define

an=theΒ numberΒ ofΒ waysΒ toΒ climbΒ nΒ stairs.a_n = \text{the number of ways to climb } n \text{ stairs}.

Now think about Fred’s last move:

  • If his last move is a single step, then before that he had climbed nβˆ’1n-1 stairs.
  • If his last move is a double step, then before that he had climbed nβˆ’2n-2 stairs.

These are the only possibilities, so

an=anβˆ’1+anβˆ’2.a_n = a_{n-1} + a_{n-2}.

The initial values are

a1=1,a2=2.a_1=1,\qquad a_2=2.

So the sequence begins

1,2,3,5,8,13,21,34,55,89.1,2,3,5,8,13,21,34,55,89.

Therefore,

a10=89.a_{10}=89.

This is the Fibonacci recurrence in disguise, which appears constantly in AMC and AIME counting problems.

Example. (2007 AMC 12) Call a set of integers spacy if it contains no more than one out of any three consecutive integers. How many subsets of {1,2,3,…,12}\{1,2,3,\dots,12\}, including the empty set, are spacy?

Solution. Let

an=theΒ numberΒ ofΒ spacyΒ subsetsΒ ofΒ {1,2,…,n}.a_n = \text{the number of spacy subsets of } \{1,2,\dots,n\}.

Now split into two cases:

  • If a spacy subset contains nn, then it cannot contain nβˆ’1n-1 or nβˆ’2n-2. So the rest of the set is a spacy subset of {1,2,…,nβˆ’3}\{1,2,\dots,n-3\}, giving anβˆ’3a_{n-3} possibilities.
  • If a spacy subset does not contain nn, then it is just a spacy subset of {1,2,…,nβˆ’1}\{1,2,\dots,n-1\}, giving anβˆ’1a_{n-1} possibilities.

Hence

an=anβˆ’1+anβˆ’3.a_n=a_{n-1}+a_{n-3}.

The initial values are

a1=2,a2=3,a3=4,a_1=2,\qquad a_2=3,\qquad a_3=4,

since the spacy subsets are:

  • for n=1n=1: βˆ…,{1}\varnothing,\{1\},
  • for n=2n=2: βˆ…,{1},{2}\varnothing,\{1\},\{2\},
  • for n=3n=3: βˆ…,{1},{2},{3}\varnothing,\{1\},\{2\},\{3\}.

Now compute forward:

a4=6,a5=9,a6=13,a7=19,a8=28,a9=41,a10=60,a11=88,a12=129.\begin{aligned} a_4&=6, & a_5&=9, & a_6&=13, \\ a_7&=19, & a_8&=28, & a_9&=41, \\ a_{10}&=60, & a_{11}&=88, & a_{12}&=129. \end{aligned}

So the answer is

129.129.

Example. (AIME 2006) A collection of eight cubes consists of one cube with edge length kk for each integer kk from 11 to 88. A tower is built using all eight cubes, and the cube immediately on top of a cube with edge length kk must have edge length at most k+2k+2. How many towers can be constructed?

Solution. Define

an=theΒ numberΒ ofΒ validΒ towersΒ usingΒ cubesΒ 1,2,…,n.a_n=\text{the number of valid towers using cubes }1,2,\dots,n.

Look at the cube of edge length nn. In a valid tower, it can be:

  • at the bottom,
  • directly above cube nβˆ’1n-1,
  • directly above cube nβˆ’2n-2.

So for each valid tower on nβˆ’1n-1 cubes, there are exactly three ways to insert cube nn. Thus

an=3anβˆ’1.a_n=3a_{n-1}.

We begin with

a2=2,a_2=2,

since either the cube of side length 11 is on the bottom and 22 is on top, or vice versa.

Then

a8=36β‹…a2=36β‹…2=1458.a_8 = 3^6 \cdot a_2 = 3^6 \cdot 2 = 1458.

This is a good reminder that some recurrences only become valid after the first few terms; here the relation is not meant to be applied at n=2n=2 itself.

Catalan numbers arise in many recursive counting problems where a structure splits naturally into a left part and a right part.

Example. How many paths are there from (0,0)(0,0) to (n,n)(n,n) using only right and up steps, such that the path never goes above the line y=xy=x?

Let

Cn=theΒ numberΒ ofΒ suchΒ pathsΒ fromΒ (0,0)Β toΒ (n,n).C_n=\text{the number of such paths from }(0,0)\text{ to }(n,n).

To get a recurrence, look at the first point (i,i)(i,i) after (0,0)(0,0) where the path returns to the diagonal.

Then:

  • the initial portion of the path contributes Ciβˆ’1C_{i-1} possibilities,
  • the remaining portion contributes Cnβˆ’iC_{n-i} possibilities.

Summing over all possible first return points gives

Cn=C0Cnβˆ’1+C1Cnβˆ’2+β‹―+Cnβˆ’1C0=βˆ‘i=0nβˆ’1CiCnβˆ’iβˆ’1.C_n = C_0C_{n-1}+C_1C_{n-2}+\cdots+C_{n-1}C_0 =\sum_{i=0}^{n-1} C_iC_{n-i-1}.

For example, when n=3n=3, there are 55 such paths.

Theorem 4.2 (Catalan Numbers). The nnth Catalan number has explicit formula

Cn=1n+1(2nn).C_n=\frac{1}{n+1}\binom{2n}{n}.

The reflection argument on the distributions and lattice paths page proves this closed form. Here the recurrence shows how it arises from splitting a path at its first return to the diagonal.

Example. How many ways are there to arrange nn open brackets and nn closed brackets so that, reading from left to right, the number of closed brackets never exceeds the number of open brackets?

Solution. This is a Catalan-number problem.

Make the following bijection:

  • each open bracket corresponds to a step to the right,
  • each closed bracket corresponds to a step upward.

Then a bracket string with nn opens and nn closes becomes a path from (0,0)(0,0) to (n,n)(n,n). The condition that the number of closed brackets never exceeds the number of open brackets means the path never goes above the line y=xy=x.

So the answer is simply

Cn=1n+1(2nn).C_n=\frac{1}{n+1}\binom{2n}{n}.

Generating functions turn linear recurrences into algebraic equations and can also help evaluate sums. This section adapts the generating-functions material from the summations handout to recurrence problems. For a nonnegative integer upper index, use (nk)=0\binom nk=0 when k<0k<0 or k>nk>n; this convention lets us write coefficient sums without extra endpoint cases.

The basic idea is this: given a sequence ana_n, package it into the formal power series

A(x)=βˆ‘nβ‰₯0anxn.A(x) = \sum_{n \ge 0} a_n x^n.

Here [xn]A(x)[x^n]A(x) denotes the coefficient of xnx^n, so [xn]A(x)=an[x^n]A(x)=a_n. We use formal power series: identities are compared coefficient by coefficient without assigning a numerical value to xx. A rearrangement is valid in this setting when each coefficient receives only finitely many contributions. If we evaluate an infinite series at a numerical xx, we must also check convergence.

Multiplying generating functions performs a convolution: [xn](A(x)B(x))=βˆ‘k=0nakbnβˆ’k[x^n](A(x)B(x))=\sum_{k=0}^n a_kb_{n-k}. This is why products describe structures built from two independent size contributions.

That lets us turn a whole sequence into one algebraic object. This is useful because:

  • A(x)A(x) may have a nice closed form.
  • The coefficients of A(x)A(x) encode the entire sequence.
  • Recurrence relations often turn into algebraic equations in A(x)A(x).
  • Once you get a rational expression for A(x)A(x), partial fractions can recover a closed form.

Example. Show that

βˆ‘nβ‰₯0(1000n)=21000.\sum_{n \ge 0} \binom{1000}{n} = 2^{1000}.

Let an=(1000n)a_n=\binom{1000}{n}. Then

A(x)=βˆ‘nβ‰₯0anxn=βˆ‘nβ‰₯0(1000n)xn=(1+x)1000.A(x)=\sum_{n \ge 0} a_nx^n=\sum_{n \ge 0}\binom{1000}{n}x^n=(1+x)^{1000}.

Plugging in x=1x=1 gives the identity immediately.

Example. Compute

βˆ‘nβ‰₯0n(1000n).\sum_{n \ge 0} n\binom{1000}{n}.

Differentiate the previous generating function:

βˆ‘nβ‰₯1n(1000n)xnβˆ’1=1000(1+x)999.\sum_{n \ge 1} n\binom{1000}{n}x^{n-1} = 1000(1+x)^{999}.

Now set x=1x=1:

βˆ‘nβ‰₯0n(1000n)=1000β‹…2999.\sum_{n \ge 0} n\binom{1000}{n}=1000\cdot 2^{999}.

Exercise 5.3. Compute

βˆ‘nβ‰₯0n2(1000n).\sum_{n \ge 0} n^2\binom{1000}{n}.

Consider the Lucas numbers LnL_n defined by

L0=2,L1=1,Ln+2=Ln+1+Ln.L_0=2,\qquad L_1=1,\qquad L_{n+2}=L_{n+1}+L_n.

The first few terms are

2,1,3,4,7,11,18,29,…2,1,3,4,7,11,18,29,\dots

Theorem 5.4 (Closed Form for Lucas Numbers). Let

Ξ±=1+52,Ξ²=1βˆ’52.\alpha=\frac{1+\sqrt5}{2}, \qquad \beta=\frac{1-\sqrt5}{2}.

Then

Ln=Ξ±n+Ξ²n.L_n=\alpha^n+\beta^n.

Proof (Lucas-number formula). Consider the generating function

L(x)=βˆ‘nβ‰₯0Lnxn=2+x+3x2+4x3+7x4+⋯ .L(x)=\sum_{n \ge 0} L_nx^n = 2+x+3x^2+4x^3+7x^4+\cdots.

Now write shifted copies:

xL(x)=2x+x2+3x3+4x4+⋯ ,xL(x)=2x+x^2+3x^3+4x^4+\cdots, x2L(x)=2x2+x3+3x4+⋯ .x^2L(x)=2x^2+x^3+3x^4+\cdots.

Because Ln+2=Ln+1+LnL_{n+2}=L_{n+1}+L_n, subtracting gives

L(x)βˆ’xL(x)βˆ’x2L(x)=2βˆ’x.L(x)-xL(x)-x^2L(x)=2-x.

So

(1βˆ’xβˆ’x2)L(x)=2βˆ’x,(1-x-x^2)L(x)=2-x,

hence

L(x)=2βˆ’x1βˆ’xβˆ’x2.L(x)=\frac{2-x}{1-x-x^2}.

Factor the denominator:

1βˆ’xβˆ’x2=(1βˆ’Ξ±x)(1βˆ’Ξ²x).1-x-x^2=(1-\alpha x)(1-\beta x).

Then partial fractions give

L(x)=11βˆ’Ξ±x+11βˆ’Ξ²x.L(x)=\frac{1}{1-\alpha x}+\frac{1}{1-\beta x}.

Expand each as a geometric series:

L(x)=βˆ‘nβ‰₯0(Ξ±x)n+βˆ‘nβ‰₯0(Ξ²x)n=βˆ‘nβ‰₯0(Ξ±n+Ξ²n)xn.L(x)=\sum_{n \ge 0}(\alpha x)^n + \sum_{n \ge 0}(\beta x)^n =\sum_{n \ge 0}(\alpha^n+\beta^n)x^n.

Matching coefficients yields

Ln=Ξ±n+Ξ²n.L_n=\alpha^n+\beta^n.

Exercise 5.5. Derive Binet’s formula for Fibonacci numbers:

Fn=15(Ξ±nβˆ’Ξ²n).F_n=\frac{1}{\sqrt5}(\alpha^n-\beta^n).

As an intermediate step, show that the Fibonacci generating function is

x1βˆ’xβˆ’x2.\frac{x}{1-x-x^2}.

We already know

11βˆ’x=1+x+x2+β‹―\frac{1}{1-x}=1+x+x^2+\cdots

and

(1+x)n=βˆ‘kβ‰₯0(nk)xk.(1+x)^n=\sum_{k \ge 0}\binom{n}{k}x^k.

The next result gives many more useful expansions.

Theorem 5.6 (Generalized Binomial Theorem). For any real number rr, the following is a formal power-series identity. As a numerical series it converges to the stated function for ∣x∣<1\lvert x\rvert<1; if rr is a nonnegative integer, it is a finite polynomial identity valid for every xx:

(1+x)r=βˆ‘nβ‰₯0(rn)xn,(1+x)^r = \sum_{n \ge 0} \binom{r}{n}x^n,

where (r0)=1\binom r0=1 and, for nβ‰₯1n\ge1,

(rn)=r(rβˆ’1)β‹―(rβˆ’n+1)n!.\binom{r}{n} = \frac{r(r-1)\cdots(r-n+1)}{n!}.

Proof (Generalized binomial coefficients). Write

(1+x)r=a0+a1x+a2x2+a3x3+β‹―(1+x)^r = a_0+a_1x+a_2x^2+a_3x^3+\cdots

and differentiate enough times to isolate the coefficient you want. For example, comparing constant terms after three derivatives gives

a3=r(rβˆ’1)(rβˆ’2)3!,an=r(rβˆ’1)β‹―(rβˆ’n+1)n!.a_3=\frac{r(r-1)(r-2)}{3!},\qquad a_n=\frac{r(r-1)\cdots(r-n+1)}{n!}.

Important consequences, interpreted formally or within their intervals of convergence:

  • Setting r=βˆ’1r=-1 gives 11+x=βˆ‘nβ‰₯0(βˆ’x)n.\frac{1}{1+x}=\sum_{n \ge 0}(-x)^n.
  • More generally, 1(1βˆ’x)m+1=βˆ‘kβ‰₯0(k+mm)xk.\frac{1}{(1-x)^{m+1}}=\sum_{k \ge 0}\binom{k+m}{m}x^k.
  • Also, xm(1βˆ’x)m+1=βˆ‘kβ‰₯0(km)xk.\frac{x^m}{(1-x)^{m+1}}=\sum_{k \ge 0}\binom{k}{m}x^k.
  • A very important identity is 11βˆ’4x=βˆ‘kβ‰₯0(2kk)xk.\frac{1}{\sqrt{1-4x}}=\sum_{k \ge 0}\binom{2k}{k}x^k.
  • Integrating that identity gives the Catalan generating function: 1βˆ’1βˆ’4x2x=βˆ‘kβ‰₯0Ckxk,\frac{1-\sqrt{1-4x}}{2x}=\sum_{k \ge 0} C_kx^k, where Ck=1k+1(2kk).C_k=\frac{1}{k+1}\binom{2k}{k}.
  • The exponential series is ex=βˆ‘kβ‰₯0xkk!.e^x=\sum_{k \ge 0}\frac{x^k}{k!}.

For quick reference:

Generating functionSequence
(1+x)n(1+x)^nβˆ‘kβ‰₯0(nk)xk\displaystyle \sum_{k \ge 0}\binom{n}{k}x^k
1(1βˆ’x)m+1\dfrac{1}{(1-x)^{m+1}}βˆ‘kβ‰₯0(k+mm)xk\displaystyle \sum_{k \ge 0}\binom{k+m}{m}x^k
xm(1βˆ’x)m+1\dfrac{x^m}{(1-x)^{m+1}}βˆ‘kβ‰₯0(km)xk\displaystyle \sum_{k \ge 0}\binom{k}{m}x^k
11βˆ’4x\dfrac{1}{\sqrt{1-4x}}βˆ‘kβ‰₯0(2kk)xk\displaystyle \sum_{k \ge 0}\binom{2k}{k}x^k
1βˆ’1βˆ’4x2x\dfrac{1-\sqrt{1-4x}}{2x}βˆ‘kβ‰₯0Ckxk\displaystyle \sum_{k \ge 0} C_kx^k
exe^xβˆ‘kβ‰₯0xkk!\displaystyle \sum_{k \ge 0}\frac{x^k}{k!}

Example. (HMMT 2007 Combinatorics #9) Let SS be the set of triples (i,j,k)(i,j,k) of positive integers satisfying i+j+k=17i+j+k=17. Compute

βˆ‘(i,j,k)∈Sijk.\sum_{(i,j,k)\in S} ijk.

Consider

F(x)=(βˆ‘iβ‰₯0ixi)(βˆ‘jβ‰₯0jxj)(βˆ‘kβ‰₯0kxk).F(x)=\left(\sum_{i \ge 0} ix^i\right)\left(\sum_{j \ge 0} jx^j\right)\left(\sum_{k \ge 0} kx^k\right).

We want the coefficient of x17x^{17}. Since

βˆ‘nβ‰₯0nxn=x(1βˆ’x)2,\sum_{n \ge 0} nx^n = \frac{x}{(1-x)^2},

we get

F(x)=(x(1βˆ’x)2)3=x3(1βˆ’x)6.F(x)=\left(\frac{x}{(1-x)^2}\right)^3 = \frac{x^3}{(1-x)^6}.

So we need the coefficient of x14x^{14} in 1(1βˆ’x)6\frac{1}{(1-x)^6}, which is

(195).\binom{19}{5}.

The β€œSnake Oil” method is a systematic way to evaluate a sum depending on a free variable. Suppose

an=βˆ‘kF(k,n).a_n=\sum_k F(k,n).

Example. For nβ‰₯0n \ge 0, compute

βˆ‘kβ‰₯0(n+k2k)2nβˆ’k.\sum_{k \ge 0}\binom{n+k}{2k}2^{n-k}.

Let

A(x)=βˆ‘nβ‰₯0[βˆ‘kβ‰₯0(n+k2k)2nβˆ’k]xn.A(x)=\sum_{n \ge 0}\left[\sum_{k \ge 0}\binom{n+k}{2k}2^{n-k}\right]x^n.

Then

A(x)=βˆ‘kβ‰₯0βˆ‘nβ‰₯0(n+k2k)2nβˆ’kxn.A(x)=\sum_{k \ge 0}\sum_{n \ge 0}\binom{n+k}{2k}2^{n-k}x^n.

After shifting indices and using

βˆ‘aβ‰₯0(a+2k2k)(2x)a=1(1βˆ’2x)2k+1,\sum_{a \ge 0}\binom{a+2k}{2k}(2x)^a = \frac{1}{(1-2x)^{2k+1}},

we obtain

A(x)=βˆ‘kβ‰₯0xk1(1βˆ’2x)2k+1=11βˆ’2xβˆ‘kβ‰₯0(x(1βˆ’2x)2)k.A(x)=\sum_{k \ge 0} x^k\frac{1}{(1-2x)^{2k+1}} = \frac{1}{1-2x}\sum_{k \ge 0}\left(\frac{x}{(1-2x)^2}\right)^k.

This is geometric:

A(x)=11βˆ’2xβ‹…11βˆ’x(1βˆ’2x)2=1βˆ’2x1βˆ’5x+4x2.A(x)=\frac{1}{1-2x}\cdot \frac{1}{1-\frac{x}{(1-2x)^2}} = \frac{1-2x}{1-5x+4x^2}.

Partial fractions give

A(x)=13β‹…11βˆ’x+23β‹…11βˆ’4x.A(x)=\frac{1}{3}\cdot \frac{1}{1-x} + \frac{2}{3}\cdot \frac{1}{1-4x}.

Therefore

A(x)=βˆ‘nβ‰₯0(13+23β‹…4n)xn,A(x)=\sum_{n \ge 0}\left(\frac13+\frac23\cdot 4^n\right)x^n,

so

βˆ‘kβ‰₯0(n+k2k)2nβˆ’k=13+23β‹…4n.\sum_{k \ge 0}\binom{n+k}{2k}2^{n-k}=\frac13+\frac23\cdot 4^n.

Example. For nβ‰₯0n \ge 0, compute

βˆ‘kβ‰₯0(knβˆ’k).\sum_{k \ge 0}\binom{k}{n-k}.

Again,

βˆ‘nβ‰₯0[βˆ‘kβ‰₯0(knβˆ’k)]xn=βˆ‘kβ‰₯0βˆ‘nβ‰₯0(knβˆ’k)xn.\sum_{n \ge 0}\left[\sum_{k \ge 0}\binom{k}{n-k}\right]x^n = \sum_{k \ge 0}\sum_{n \ge 0}\binom{k}{n-k}x^n.

Rewrite using xkx^k:

=βˆ‘kβ‰₯0xkβˆ‘k≀n≀2k(knβˆ’k)xnβˆ’k=βˆ‘kβ‰₯0xk(1+x)k.= \sum_{k \ge 0} x^k \sum_{k \le n \le 2k}\binom{k}{n-k}x^{n-k} = \sum_{k \ge 0} x^k(1+x)^k.

Thus

=11βˆ’x(1+x)=11βˆ’xβˆ’x2.= \frac{1}{1-x(1+x)} = \frac{1}{1-x-x^2}.

This is the Fibonacci generating function, so the sum equals Fn+1F_{n+1}.

If the free variable appears in many places at once, Snake Oil often works better after you first generalize the identity.

Problem 5.11. Prove that for every integer nβ‰₯0n \ge 0,

βˆ‘a+b=n(2aa)(2bb)=4n.\sum_{a+b=n}\binom{2a}{a}\binom{2b}{b}=4^n.

Problem 5.12. For integers m,nβ‰₯0m,n \ge 0, prove that

βˆ‘a+b=m(βˆ’1)a(na)(n+bβˆ’1b)={1m=0,0m>0.\sum_{a+b=m}(-1)^a \binom{n}{a}\binom{n+b-1}{b} = \begin{cases} 1 & m=0, \\ 0 & m>0. \end{cases}

Problem 5.13. Let m≀nm \le n be positive integers. Compute

βˆ‘k=mn(nk)(km).\sum_{k=m}^{n}\binom{n}{k}\binom{k}{m}.

Problem 5.14. For m,nβ‰₯1m,n \ge 1, compute

βˆ‘kβ‰₯0(n+km+2k)(2kk)(βˆ’1)kk+1.\sum_{k \ge 0}\binom{n+k}{m+2k}\binom{2k}{k}\frac{(-1)^k}{k+1}.

A single count ana_n may not contain enough information to extend a structure by one step. Define several states that record exactly the feature affecting the next choice. Extra history that cannot influence later moves is unnecessary; missing relevant history leads to an incorrect recurrence.

For strings with forbidden runs, the length of the current trailing run is a natural state. For tilings, record the shape of the unfinished boundary. For a random walk, record the current position and any feature that changes the transition rule.

Example. Find the number of binary strings of length eight containing no three consecutive ones, and derive a generating function for the counts.

Let ana_n count valid strings of length nn, with a0=1a_0=1 for the empty string. A valid string ends with zero, with zero followed by one, or with zero followed by two ones, except for the short strings handled by initial values. For nβ‰₯3n\ge3 this gives

an=anβˆ’1+anβˆ’2+anβˆ’3,a0=1,Β a1=2,Β a2=4.a_n=a_{n-1}+a_{n-2}+a_{n-3},\qquad a_0=1,\ a_1=2,\ a_2=4.

Equivalently, use states for trailing runs of zero, one, or two ones. Appending zero sends every state to the first; appending one advances the run length and is forbidden from the third state.

The counts are 1,2,4,7,13,24,44,81,1491,2,4,7,13,24,44,81,149, so the answer is 149149. Multiplying A(x)=βˆ‘nβ‰₯0anxnA(x)=\sum_{n\ge0}a_nx^n by the recurrence denominator leaves only the initial corrections:

(1βˆ’xβˆ’x2βˆ’x3)A(x)=1+x+x2.(1-x-x^2-x^3)A(x)=1+x+x^2.

Thus A(x)=(1+x+x2)/(1βˆ’xβˆ’x2βˆ’x3)A(x)=(1+x+x^2)/(1-x-x^2-x^3). The numerator records the initial conditions rather than being an arbitrary adjustment.


For a repeated nonzero characteristic root rr, the two independent solutions are rnr^n and nrnnr^n. The extra factor of nn is necessary because two constant multiples of the same geometric sequence would supply only one free initial condition.

Example. Solve an=6anβˆ’1βˆ’9anβˆ’2a_n=6a_{n-1}-9a_{n-2} with a0=1,a1=6a_0=1,a_1=6.

The characteristic polynomial is (tβˆ’3)2(t-3)^2, so use an=(A+Bn)3na_n=(A+Bn)3^n. The first value gives A=1A=1, and the second gives 3(1+B)=63(1+B)=6, hence B=1B=1. Therefore

an=(n+1)3n.a_n=(n+1)3^n.

Substitution verifies the recurrence. Together with the two initial values, uniqueness of the recursively defined sequence proves the formula.

For a nonhomogeneous recurrence, first solve the homogeneous part and then find one particular solution. If the forcing term already resembles a homogeneous solution, multiply the trial by nn, or by a higher power of nn when there is repeated overlap. This is the discrete counterpart of resonance in differential equations.

Example. Solve an+1=2an+2na_{n+1}=2a_n+2^n with a0=0a_0=0.

A trial C2nC2^n fails because the homogeneous recurrence already has that form. Instead, divide by the common geometric factor. Let bn=an/2nb_n=a_n/2^n. Then

bn+1=bn+12.b_{n+1}=b_n+\frac12.

With b0=0b_0=0, we obtain bn=n/2b_n=n/2 and an=n2nβˆ’1a_n=n2^{n-1}. This transformation also explains why the factor of nn appears.


The apparent degree of a recurrence can be misleading. A reciprocal, shift, or ratio may reveal a linear relation. Choose the substitution by examining how the operation changes the denominator or the fixed points.

Example. A sequence satisfies a0=1/2a_0=1/2 and an+1=an/(1+an)a_{n+1}=a_n/(1+a_n). Find ana_n and its limit.

All terms remain positive, so reciprocals are allowed. Set bn=1/anb_n=1/a_n. The recurrence becomes

bn+1=bn+1,b0=2.b_{n+1}=b_n+1,\qquad b_0=2.

Hence bn=n+2b_n=n+2 and an=1/(n+2)a_n=1/(n+2). The terms tend to zero. Guessing the limit from the fixed-point equation alone would not have proved convergence; the explicit formula proves both the values and the limit.

For recurrences involving two coupled quantities, an invariant can be more useful than a closed form. Under the update

xβ€²=3x+4y,yβ€²=2x+3y,x'=3x+4y,\qquad y'=2x+3y,

direct expansion gives xβ€²2βˆ’2yβ€²2=x2βˆ’2y2x'^2-2y'^2=x^2-2y^2. Starting from (3,2)(3,2) therefore produces integer solutions of x2βˆ’2y2=1x^2-2y^2=1 forever. When the question concerns divisibility or an equation satisfied by the terms, this invariant may answer it without diagonalizing the update.


Ordinary generating functions multiply by convolution because the coefficient records only the total size. For labeled objects, an exponential generating function uses anxn/n!a_nx^n/n! instead. The factorial denominator makes multiplication insert the binomial coefficient choosing which labels belong to each component:

n![xn](βˆ‘iaixii!)(βˆ‘jbjxjj!)=βˆ‘i=0n(ni)aibnβˆ’i.n![x^n]\left(\sum_i\frac{a_ix^i}{i!}\right) \left(\sum_j\frac{b_jx^j}{j!}\right) =\sum_{i=0}^n\binom ni a_ib_{n-i}.

Use the ordinary version for counts where sizes split without choosing labels, and the exponential version when distributing distinct labels among components. The two conventions encode different counting rules; switching between them without changing coefficients changes the problem.

For example, assigning nn distinct objects to three named nonempty boxes is counted by n![xn](exβˆ’1)3n![x^n](e^x-1)^3. Expanding the cube gives 3nβˆ’3β‹…2n+33^n-3\cdot2^n+3 for nβ‰₯1n\ge1, agreeing with inclusion–exclusion. This connection explains why generating functions can recover formulas first found by a completely different method.


These are good recursion problems to revisit after you are comfortable with the examples above.

Exercise 5.1. How many ways are there to tile a 10Γ—210 \times 2 board with 1Γ—21 \times 2 dominoes?

Exercise 5.2 (AMC 12 2019). How many binary sequences of length 1919 begin with 00, end with 00, contain no two consecutive 00β€˜s, and contain no three consecutive 11β€˜s?

Exercise 5.3 (AIME 2015). There are 210=10242^{10}=1024 possible 1010-letter strings using only AA and BB. How many do not contain more than three adjacent identical letters?

Exercise 5.4. Given a regular 2n2n-gon, how many ways are there to pair vertices with nonintersecting chords?

Exercise 5.5 (AIME 2001). A mail carrier delivers mail to the nineteen houses on one side of Elm Street. No two adjacent houses receive mail on the same day, and there are never more than two consecutive houses that get no mail. How many delivery patterns are possible?