evan's notes
cal 3discreteodeenv systems

On this page

  • Recursive and explicit definitions
  • Example: factorials
  • Example: a geometric recurrence
  • Counting with a recurrence: Tower of Hanoi
  • Linear first-order recurrences
  • The homogeneous recurrence
  • Finding a particular solution
  • Choosing the trial form

Discrete Structures

§4 Recurrence Relations

Evan Luo · Sep 15, 2026

Discrete Structures

§4 Recurrence Relations

Evan LuoToday

6 min read

A recurrence relation defines each term of a sequence from earlier terms. It is useful when a problem naturally breaks into a smaller copy of itself.

Recursive and explicit definitions

Let (an)n∈N(a_n)_{n\in\mathbb N}(an​)n∈N​ be a sequence, read as “the sequence ana_nan​ indexed by the natural numbers.” A first-order recurrence uses only the preceding term. It needs two parts:

  1. a base case, such as a0=ca_0=ca0​=c;
  2. a recurrence rule, such as
an=F(n,an−1)(n≥1).a_n=F(n,a_{n-1})\qquad(n\ge1). an​=F(n,an−1​)(n≥1).

Here, nnn is the index, an−1a_{n-1}an−1​ is the preceding term, and FFF is the rule that produces the next term.

An explicit formula, also called a closed form, gives ana_nan​ directly from nnn:

an=φ(n).a_n=\varphi(n). an​=φ(n).

The symbol φ\varphiφ is the Greek letter phi, read “fee.” A recurrence tells us how to compute forward; a closed form lets us jump directly to any index.

Example: factorials

The factorial sequence has base case

0!=10!=1 0!=1

and recurrence

n!=n(n−1)!(n≥1).n!=n(n-1)!\qquad(n\ge1). n!=n(n−1)!(n≥1).

For example,

4!=4⋅3!=4⋅3⋅2!=4⋅3⋅2⋅1!=4⋅3⋅2⋅1⋅0!=24.\begin{aligned} 4! &=4\cdot3!\\ &=4\cdot3\cdot2!\\ &=4\cdot3\cdot2\cdot1!\\ &=4\cdot3\cdot2\cdot1\cdot0!\\ &=24. \end{aligned} 4!​=4⋅3!=4⋅3⋅2!=4⋅3⋅2⋅1!=4⋅3⋅2⋅1⋅0!=24.​

Each substitution reduces the index until it reaches the base case.

Example: a geometric recurrence

Suppose

{a0=c,an=ran−1(n≥1),\begin{cases} a_0=c,\\ a_n=r a_{n-1}\qquad(n\ge1), \end{cases} {a0​=c,an​=ran−1​(n≥1),​

where ccc is the initial value and rrr is a fixed multiplier. Expanding several terms gives

a1=cr,a2=cr2,a3=cr3.a_1=cr, \qquad a_2=cr^2, \qquad a_3=cr^3. a1​=cr,a2​=cr2,a3​=cr3.

The pattern leads to the closed form

an=crn.\boxed{a_n=cr^n}. an​=crn​.

A proposed closed form should satisfy both the base case and the recurrence. Those two checks confirm that it describes the same sequence.

Counting with a recurrence: Tower of Hanoi

The Tower of Hanoi puzzle has three pegs and nnn disks of different sizes. All disks begin on the first peg, largest at the bottom. The goal is to move the entire stack to the third peg while following two rules:

  • move only one disk at a time;
  • never place a larger disk on top of a smaller one.

Let hnh_nhn​ be the minimum number of legal moves needed for nnn disks. The empty puzzle gives the base case

h0=0.h_0=0. h0​=0.

To solve the puzzle for n≥1n\ge1n≥1:

  1. move the top n−1n-1n−1 disks to the middle peg, using hn−1h_{n-1}hn−1​ moves;
  2. move the largest disk to the final peg, using one move;
  3. move the n−1n-1n−1 smaller disks onto it, using another hn−1h_{n-1}hn−1​ moves.

One legal solution for n disks

Tower of Hanoi recurrenceFour states show the top n minus one disks moving to the middle peg, the largest disk moving to the final peg, and the top disks moving onto it. The move count is h sub n minus one, plus one, plus h sub n minus one.hₙ₋₁ moves1 movehₙ₋₁ movesStartMove the top n − 1 disksMove the largest diskRepeat the smallerproblemhₙ = hₙ₋₁ + 1 + hₙ₋₁ = 2hₙ₋₁ + 1
Solving the n-disk puzzle contains two copies of the same problem with n − 1 disks, separated by one move of the largest disk.

Therefore,

hn=2hn−1+1.\boxed{h_n=2h_{n-1}+1}. hn​=2hn−1​+1​.

The first values are

h0=0,h1=1,h2=3,h3=7,h4=15,h5=31.h_0=0, \quad h_1=1, \quad h_2=3, \quad h_3=7, \quad h_4=15, \quad h_5=31. h0​=0,h1​=1,h2​=3,h3​=7,h4​=15,h5​=31.

These values are one less than successive powers of two. To derive the pattern, add 111 to both sides of the recurrence:

hn+1=2(hn−1+1).h_n+1=2(h_{n-1}+1). hn​+1=2(hn−1​+1).

If bn=hn+1b_n=h_n+1bn​=hn​+1, then b0=1b_0=1b0​=1 and bn=2bn−1b_n=2b_{n-1}bn​=2bn−1​. This is a geometric recurrence, so bn=2nb_n=2^nbn​=2n. Hence

hn=2n−1.\boxed{h_n=2^n-1}. hn​=2n−1​.

For the traditional puzzle with 64 disks,

h64=264−1=18,446,744,073,709,551,615h_{64}=2^{64}-1 =18{,}446{,}744{,}073{,}709{,}551{,}615 h64​=264−1=18,446,744,073,709,551,615

moves. At one move per second, that is about 1.84×10191.84\times10^{19}1.84×1019 seconds, or 5.85×10115.85\times10^{11}5.85×1011 years—roughly 42 times the current age of the universe.

Linear first-order recurrences

A linear first-order recurrence has the form

{a0=c,an=f(n)an−1+g(n)(n≥1),\begin{cases} a_0=c,\\ a_n=f(n)a_{n-1}+g(n)\qquad(n\ge1), \end{cases} {a0​=c,an​=f(n)an−1​+g(n)(n≥1),​

where f(n)f(n)f(n) and g(n)g(n)g(n) are known functions. The term g(n)g(n)g(n) is called the nonhomogeneous term or forcing term.

Consider

{a0=3,an=2an−1+n.\begin{cases} a_0=3,\\ a_n=2a_{n-1}+n. \end{cases} {a0​=3,an​=2an−1​+n.​

Computing forward gives the sequence

3,7,16,35,74,…3,7,16,35,74,\ldots 3,7,16,35,74,…

To find a closed form, separate the recurrence into its homogeneous behavior and a particular response to the forcing term.

The homogeneous recurrence

Remove the forcing term g(n)g(n)g(n) to get the associated homogeneous recurrence:

hn=f(n)hn−1.h_n=f(n)h_{n-1}. hn​=f(n)hn−1​.

For the example, this becomes

hn=2hn−1,h_n=2h_{n-1}, hn​=2hn−1​,

whose general solution is

hn=C⋅2n,h_n=C\cdot2^n, hn​=C⋅2n,

where CCC is an arbitrary constant.

A particular solution is any one sequence that satisfies the full recurrence. Suppose (pn)(p_n)(pn​) and (qn)(q_n)(qn​) are two particular solutions. Subtracting their equations cancels the forcing term:

pn−qn=f(n)pn−1+g(n)−(f(n)qn−1+g(n))=f(n)(pn−1−qn−1).\begin{aligned} p_n-q_n &=f(n)p_{n-1}+g(n)-\bigl(f(n)q_{n-1}+g(n)\bigr)\\ &=f(n)(p_{n-1}-q_{n-1}). \end{aligned} pn​−qn​​=f(n)pn−1​+g(n)−(f(n)qn−1​+g(n))=f(n)(pn−1​−qn−1​).​

Thus, the difference between any two particular solutions satisfies the homogeneous recurrence. Once one particular solution pnp_npn​ is known, every solution has the form

an=pn+hn.\boxed{a_n=p_n+h_n}. an​=pn​+hn​​.

Finding a particular solution

For

an=2an−1+n,a_n=2a_{n-1}+n, an​=2an−1​+n,

the forcing term g(n)=ng(n)=ng(n)=n is a polynomial of degree one. Guess a particular solution of the same form:

pn=An+B,p_n=An+B, pn​=An+B,

where AAA and BBB are constants to determine. Substitute the guess into the recurrence:

An+B=2(A(n−1)+B)+n=(2A+1)n+(−2A+2B).\begin{aligned} An+B &=2\bigl(A(n-1)+B\bigr)+n\\ &=(2A+1)n+(-2A+2B). \end{aligned} An+B​=2(A(n−1)+B)+n=(2A+1)n+(−2A+2B).​

Matching the coefficients of nnn and the constant terms gives

A=2A+1,B=−2A+2B.A=2A+1, \qquad B=-2A+2B. A=2A+1,B=−2A+2B.

Therefore,

A=−1,B=−2,A=-1, \qquad B=-2, A=−1,B=−2,

so one particular solution is

pn=−n−2.p_n=-n-2. pn​=−n−2.

Add the homogeneous solution:

an=−n−2+C⋅2n.a_n=-n-2+C\cdot2^n. an​=−n−2+C⋅2n.

Use the base case a0=3a_0=3a0​=3:

3=−2+C,C=5.3=-2+C, \qquad C=5. 3=−2+C,C=5.

The closed form is

an=5⋅2n−n−2.\boxed{a_n=5\cdot2^n-n-2}. an​=5⋅2n−n−2​.

Checking n=0n=0n=0 gives a0=3a_0=3a0​=3, and substituting the formula into the recurrence gives an=2an−1+na_n=2a_{n-1}+nan​=2an−1​+n.

Choosing the trial form

The trial-form shortcut below applies to a constant-coefficient recurrence

an=ran−1+g(n),a_n=r a_{n-1}+g(n), an​=ran−1​+g(n),

where rrr is fixed. In this case, the shape of g(n)g(n)g(n) suggests a useful guess for pnp_npn​:

Forcing term g(n)g(n)g(n)Trial particular solution pnp_npn​
polynomial of degree dddA0+A1n+⋯+AdndA_0+A_1n+\cdots+A_dn^dA0​+A1​n+⋯+Ad​nd
cbncb^ncbnAbnAb^nAbn
a sum of termsthe sum of the corresponding trial forms
a product of a polynomial and bnb^nbna polynomial of the same degree multiplied by bnb^nbn

For example, if

g(n)=2n+n23n,g(n)=2^n+n^2 3^n, g(n)=2n+n23n,

try

pn=A2n+(B+Cn+Dn2)3n.p_n=A2^n+(B+Cn+Dn^2)3^n. pn​=A2n+(B+Cn+Dn2)3n.

There is one important exception. If the trial already has the same form as a homogeneous solution, it will cancel during substitution. Multiply the trial by nnn—and by a higher power of nnn if necessary—until the forms no longer overlap. When g(n)g(n)g(n) is a sum, adjust only the overlapping part of the trial.

For this constant-coefficient case, the complete method is:

  1. solve the associated homogeneous recurrence to obtain hnh_nhn​;
  2. choose a trial pnp_npn​ from the form of g(n)g(n)g(n);
  3. substitute pnp_npn​ into the original recurrence and solve for its coefficients;
  4. write an=pn+hna_n=p_n+h_nan​=pn​+hn​;
  5. use the base case to determine the remaining constant.

Source: https://notes.ohevan.com/notes/discrete-structures/04-recurrence-relations

© 2026 Evan Luo. All rights reserved.

Back to Discrete Structures

0 reads

  • stay up to date

  • about me

  • coffee

© 2026 Evan Luo. All rights reserved.