evan's notes
cal 3discreteodeenv systems
English

本页目录

  • Recursive 与 explicit definitions
  • 例:factorials
  • 例:geometric recurrence
  • 用 recurrence 计数:Tower of Hanoi
  • Linear first-order recurrences
  • Homogeneous recurrence
  • 求 particular solution
  • 如何选择 trial form
  • Higher-order recurrences
  • Characteristic equations
  • 另一个 characteristic-root 例题
  • 其他情况有什么变化

Discrete Structures:离散结构

§4 Recurrence relations:递推关系

Evan Luo · 2026年9月15日

Discrete Structures:离散结构

§4 Recurrence relations:递推关系

Evan Luo2026年9月15日

12 分钟

Recurrence relation 用一个数列前面的项来定义后面的项。当问题能自然地拆成一个规模更小的同类问题时,这种表达方式就很有用。

Recursive 与 explicit definitions

设 (an)n∈N(a_n)_{n\in\mathbb N}(an​)n∈N​ 是一个数列,读作“以自然数为下标的数列 ana_nan​”。First-order recurrence 只用到前一项,需要给出两部分:

  1. 一个 base case,例如 a0=ca_0=ca0​=c;
  2. 一条 recurrence rule,例如
an=F(n,an−1)(n≥1).a_n=F(n,a_{n-1})\qquad(n\ge1). an​=F(n,an−1​)(n≥1).

这里 nnn 是下标,an−1a_{n-1}an−1​ 是前一项,FFF 是用来计算下一项的规则。

Explicit formula,也叫 closed form,直接根据 nnn 给出 ana_nan​:

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

符号 φ\varphiφ 是希腊字母 phi,读作“fee”。Recurrence 让我们逐项往后算;closed form 则让我们直接算出任意下标对应的项。

例:factorials

Factorial 数列的 base case 是

0!=10!=1 0!=1

recurrence 是

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

例如,

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.​

每代入一次,下标就减小一步,直到回到 base case。

例:geometric recurrence

假设

{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),​

其中 ccc 是初值,rrr 是固定的乘数。展开前几项得到

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.

由此得到 closed form:

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

检验一个候选 closed form 时,要同时检查它是否满足 base case 和 recurrence。这两项检查能确认它给出的确实是同一个数列。若乘数为零,初值仍按定义取给定值,之后各项都为零;不必通过零的零次幂来确定初值。

用 recurrence 计数:Tower of Hanoi

Tower of Hanoi 有三根柱子和 nnn 个大小不同的圆盘。起初所有盘子都在第一根柱子上,最大的在最底下。目标是在遵守两条规则的前提下,把整叠盘子移到第三根柱子:

  • 每次只能移动一个盘子;
  • 不能把大盘放在小盘上面。

设 hnh_nhn​ 表示移动 nnn 个盘子所需的最少合法步数。没有盘子时不需要移动,因此 base case 是

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

当 n≥1n\ge1n≥1 时,可以这样完成:

  1. 把上面的 n−1n-1n−1 个盘子移到中间的柱子,需要 hn−1h_{n-1}hn−1​ 步;
  2. 把最大的盘子移到目标柱子,需要一步;
  3. 把 n−1n-1n−1 个小盘移到大盘上,再用 hn−1h_{n-1}hn−1​ 步。

One legal solution fornnndisks

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.
hn−1h_{n-1}hn−1​moves
111move
hn−1h_{n-1}hn−1​moves
Start
Move the topn−1n-1n−1disks
Move the largest disk
Repeat the smaller
problem
hn=hn−1+1+hn−1=2hn−1+1h_n = h_{n-1} + 1 + h_{n-1} = 2h_{n-1} + 1hn​=hn−1​+1+hn−1​=2hn−1​+1
Solving thennn-disk puzzle contains two copies of the same problem withn−1n-1n−1disks, separated by one move of the largest disk.

这个方法给出了一个可行的步数,也确实达到了最少步数。最大盘第一次移动前,所有小盘必须先移到另一根柱子上;最大盘最后一次移动到目标柱子后,所有小盘又必须从另一根柱子移到它上面。这两段各至少需要一次小规模问题的最少步数,而最大盘至少要移动一次。因此,

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

最初几项是

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.

这些值都比相应的二的幂少一。要推导这个规律,在 recurrence 两边都加上 111:

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

令 bn=hn+1b_n=h_n+1bn​=hn​+1,则 b0=1b_0=1b0​=1,且 bn=2bn−1b_n=2b_{n-1}bn​=2bn−1​。这是 geometric recurrence,所以 bn=2nb_n=2^nbn​=2n。因此,

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

传统的 64 个盘子的版本需要

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

步。若每秒移动一次,就需要约 1.84×10191.84\times10^{19}1.84×1019 秒,也就是 5.85×10115.85\times10^{11}5.85×1011 年。以宇宙年龄约 138 亿年估算,这大约是它的 42 倍。

Linear first-order recurrences

Linear first-order recurrence 的形式为

{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),​

其中 f(n)f(n)f(n) 和 g(n)g(n)g(n) 是已知函数。g(n)g(n)g(n) 称为 nonhomogeneous term,也叫 forcing term。

考虑

{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.​

逐项计算得到

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

为了求出 closed form,可以先求去掉 forcing term 后的 homogeneous solution,再找一个能满足完整 recurrence 的 particular solution。

Homogeneous recurrence

去掉 forcing term g(n)g(n)g(n),得到对应的 homogeneous recurrence:

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

在这个例子中,它是

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

通解为

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

其中 CCC 是任意常数。

Particular solution 是满足完整 recurrence 的某一个数列,这里暂不要求它满足指定的初值。设 (pn)(p_n)(pn​) 和 (qn)(q_n)(qn​) 是两个 particular solutions。把它们的等式相减,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​).​

所以,任意两个 particular solutions 的差都满足 homogeneous recurrence。只要找到一个 particular solution pnp_npn​,每个解都能写成

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

求 particular solution

对于

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

forcing term g(n)=ng(n)=ng(n)=n 是一次多项式。因此先尝试同样形式的 particular solution:

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

其中 AAA、BBB 是待定常数。把这个形式代入 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).​

比较 nnn 的系数和常数项,得到

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

因此,

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

所以一个 particular solution 是

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

再加上 homogeneous solution:

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

最后使用 base case a0=3a_0=3a0​=3:

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

得到 closed form:

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

代入 n=0n=0n=0 得到 a0=3a_0=3a0​=3;再把公式代入 recurrence,也能验证 an=2an−1+na_n=2a_{n-1}+nan​=2an−1​+n。

如何选择 trial form

下面选择 trial form 的方法适用于 constant-coefficient recurrence

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

其中 rrr 是常数。在这种情况下,可以根据 g(n)g(n)g(n) 的形式来选择 pnp_npn​:

Forcing term g(n)g(n)g(n)Trial particular solution pnp_npn​
次数为 ddd 的多项式A0+A1n+⋯+AdndA_0+A_1n+\cdots+A_dn^dA0​+A1​n+⋯+Ad​nd
cbncb^ncbnAbnAb^nAbn
多项之和各项对应的 trial form 相加
多项式与 bnb^nbn 的乘积同次数的多项式乘以 bnb^nbn

例如,如果

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

先尝试

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

还需要检查 trial form 是否与 homogeneous solution 重叠。如果重叠,代入时相关项会抵消,就无法匹配 forcing term。此时把 trial form 乘以 nnn;必要时乘以 nnn 的更高次幂,直到消除重叠。若 g(n)g(n)g(n) 是几项之和,只调整其中重叠的那一部分。

对这种 constant-coefficient 情况,完整步骤是:

  1. 解对应的 homogeneous recurrence,得到 hnh_nhn​;
  2. 根据 g(n)g(n)g(n) 的形式选择 trial pnp_npn​;
  3. 把 pnp_npn​ 代入原 recurrence,解出待定系数;
  4. 写出 an=pn+hna_n=p_n+h_nan​=pn​+hn​;
  5. 用 base case 确定剩下的常数。

Higher-order recurrences

Order 为 222 的 recurrence 可以用到前两项,因此需要两个 base cases。一个常见的例子是下标平移后的 Fibonacci sequence:

{f0=1,f1=2,fn=fn−1+fn−2(n≥2).\begin{cases} f_0=1,\\ f_1=2,\\ f_n=f_{n-1}+f_{n-2}\qquad(n\ge2). \end{cases} ⎩⎨⎧​f0​=1,f1​=2,fn​=fn−1​+fn−2​(n≥2).​

逐项计算得到

1,2,3,5,8,13,21,34,…,1,2,3,5,8,13,21,34,\ldots, 1,2,3,5,8,13,21,34,…,

特别地,

f12=377.f_{12}=377. f12​=377.

这个下标约定对应一种兔群模型:从一对已经能繁殖的兔子开始,并把第零个月已有的这一对也计入。Recurrence 适合按顺序计算各项,而 characteristic equation 能帮助我们直接写出 fnf_nfn​ 的公式。

Characteristic equations

对 constant coefficients 的 homogeneous second-order recurrence,

an=C1an−1+C2an−2,a_n=C_1a_{n-1}+C_2a_{n-2}, an​=C1​an−1​+C2​an−2​,

可以借鉴一阶 geometric recurrence,尝试 exponential solution an=xna_n=x^nan​=xn。代入得到

xn=C1xn−1+C2xn−2.x^n=C_1x^{n-1}+C_2x^{n-2}. xn=C1​xn−1+C2​xn−2.

当 xxx 非零时,两边除以 xn−2x^{n-2}xn−2,得到 characteristic equation。以下按真正二阶的情形讨论,即最早一项的系数 C2C_2C2​ 非零;这样 characteristic roots 也不会为零。

x2−C1x−C2=0.x^2-C_1x-C_2=0. x2−C1​x−C2​=0.

对 Fibonacci recurrence,方程是

x2−x−1=0.x^2-x-1=0. x2−x−1=0.

它的两个根为

φ=1+52,φˉ=1−52.\varphi=\frac{1+\sqrt5}{2}, \qquad \bar\varphi=\frac{1-\sqrt5}{2}. φ=21+5​​,φˉ​=21−5​​.

φ\varphiφ 是 golden ratio。另一个根 φˉ\bar\varphiφˉ​ 为负数,而且其 absolute value 小于一。

单独一个 exponential solution 通常不能同时满足两个独立的 base cases。若有两个不同的 characteristic roots,则每个解都是它们对应解的 linear combination:

fn=Aφn+Bφˉn.f_n=A\varphi^n+B\bar\varphi^n. fn​=Aφn+Bφˉ​n.

两个 base cases 给出方程组

1=A+B,2=Aφ+Bφˉ.1=A+B, \qquad 2=A\varphi+B\bar\varphi. 1=A+B,2=Aφ+Bφˉ​.

解得

A=5+325,B=5−325.A=\frac{\sqrt5+3}{2\sqrt5}, \qquad B=\frac{\sqrt5-3}{2\sqrt5}. A=25​5​+3​,B=25​5​−3​.

因此,

fn=5+325φn+5−325φˉn.\boxed{ f_n= \frac{\sqrt5+3}{2\sqrt5}\varphi^n + \frac{\sqrt5-3}{2\sqrt5}\bar\varphi^n }. fn​=25​5​+3​φn+25​5​−3​φˉ​n​.

也可以写成

fn=φn+2−φˉn+25.f_n=\frac{\varphi^{n+2}-\bar\varphi^{n+2}}{\sqrt5}. fn​=5​φn+2−φˉ​n+2​.

由于 φ>1\varphi>1φ>1,而 ∣φˉ∣<1|\bar\varphi|<1∣φˉ​∣<1,长期增长由第一项决定;第二项的 absolute value 会逐渐减小,符号则不断交替。

Fibonacci growth from characteristic roots

Shifted Fibonacci growth and conjugate-root correctionThe upper panel compares shifted Fibonacci values with the dominant characteristic-root term. The lower panel magnifies the small conjugate-root correction, which alternates in sign and shrinks toward zero.Sequence growthAlternating correction term0246810120100200300400-0.20.00.2Index
  • fn​recurrence values
  • Aφndominant-root term
  • Bφˉ​nconjugate-root correction
The root φ is greater than one. In the upper panel, Aφn controls the visible growth while the points mark the exact recurrence values. The lower panel magnifies Bφˉ​n, showing why the correction alternates in sign and shrinks toward zero.

另一个 characteristic-root 例题

考虑

{an=an−1+2an−2,a0=2,a1=7.\begin{cases} a_n=a_{n-1}+2a_{n-2},\\ a_0=2,\\ a_1=7. \end{cases} ⎩⎨⎧​an​=an−1​+2an−2​,a0​=2,a1​=7.​

Characteristic equation 是

x2−x−2=0,x^2-x-2=0, x2−x−2=0,

两个根为 r1=−1r_1=-1r1​=−1 和 r2=2r_2=2r2​=2。因此,

an=A(−1)n+B2n.a_n=A(-1)^n+B2^n. an​=A(−1)n+B2n.

由 base cases 得到

2=A+B,7=−A+2B,2=A+B, \qquad 7=-A+2B, 2=A+B,7=−A+2B,

所以 A=−1A=-1A=−1、B=3B=3B=3。Closed form 为

an=−(−1)n+3⋅2n.\boxed{a_n=-(-1)^n+3\cdot2^n}. an​=−(−1)n+3⋅2n​.

其他情况有什么变化

  • Repeated root: 若 characteristic polynomial 只有一个非零 double root rrr,两个独立的 basis solutions 是 rnr^nrn 和 nrnnr^nnrn,因此通解为 (A+Bn)rn(A+Bn)r^n(A+Bn)rn。
  • Complex roots: 同样的方法也适用于 complex numbers;一对 conjugate roots 对应的解可以组合成实数的 sine-cosine 形式。
  • Nonhomogeneous recurrence: 先解 homogeneous recurrence,再找一个 particular solution,然后相加:an=hn+pna_n=h_n+p_nan​=hn​+pn​。
  • Order 大于二: 方法仍然适用,但 characteristic polynomial 的次数与 recurrence 的 order 相同。例如,
an=an−1+an−2−an−3a_n=a_{n-1}+a_{n-2}-a_{n-3} an​=an−1​+an−2​−an−3​

给出

x3−x2−x+1=0.x^3-x^2-x+1=0. x3−x2−x+1=0.

Characteristic polynomial 方法要求 recurrence 是 linear 且具有 constant coefficients。Variable coefficients 或 nonlinear terms 需要其他方法。若最早一项的系数为零,应先检查是否已经降阶,并单独处理初值,不要直接套用上面的非零根公式。

来源: https://notes.ohevan.com/zh/notes/discrete-structures/04-recurrence-relations

© 2026 Evan Luo. 保留所有权利。

返回 Discrete Structures:离散结构

0 次阅读

·最后编辑 今天
  • 邮件订阅

  • 关于我

  • 赞助

© 2026 Evan Luo. 保留所有权利。