016. Number of Cases and Recurrence Relation

Consider the situation of making words with only three letters: aa, bb, and cc. If the letters aa and bb cannot be arranged adjacent to each other, find the number of all words whose length is nn.


Let AnA_n be the answer to find, and set A0=1A_0 = 1. Also, trivially, A1=3A_1 = 3.

Now, if n≥2n \ge 2, it can be classified as follows.

  • (1) There is cc in the first position.
    • Excluding cc, it is the same as the number of cases to create a word with the remaining n−1n - 1 letters.
    • So, An−1A_{n - 1}.
  • (2) cc appears for the first time in the kk-th position where 2≤k≤n2 \le k \le n.
    • aa and bb must appear alternately up to the k−1k-1-th time.
    • Excluding the first kk letters, the rest is equal to the number of cases to make a word with n−kn - k letters.
    • So, 2An−k2 A_{n - k}.
  • (3) There is no cc.
    • The only two cases are acceptable: aba...aba... and bab...bab...
    • So, 22.

Putting together the above, the recurrence relation is as follows. An=An−1+2An−2+⋯+2A0+2An−1=An−2+2An−3+⋯+2A0+2An−An−1=An−1+An−2  ⟹  An−2An−1−An−2=0  ⟹  An+1−2An−An−1=0(n≥1)\begin{aligned} A_n &= A_{n-1} + 2 A_{n-2} + \cdots + 2 A_0 + 2 \\ A_{n-1} &= A_{n-2} + 2 A_{n-3} + \cdots + 2 A_0 + 2 \\ A_n - A_{n-1} &= A_{n-1} + A_{n-2} \\\\ \implies &A_n - 2 A_{n-1} - A_{n-2} = 0 \\ \implies &A_{n+1} - 2 A_n - A_{n-1} = 0 \quad (n \ge 1) \end{aligned}

This form of recurrence relation can be solved as a quadratic equation. It is the same process as finding the general term of the Fibonacci sequence. If this relation is transformed into the following quadratic equation, a simultaneous equation can be established by finding the two roots α\alpha and β\beta of this equation. An+1−2An−An−1=An+1−(α+β)An+αβAn−1=0  ⟹  x2−2x−1=0  ⟹  α=1−2,β=1+2,α+β=2,αβ=−1\begin{aligned} &A_{n+1} - 2 A_n - A_{n-1} = A_{n+1} - (\alpha + \beta) A_n + \alpha \beta A_{n-1} = 0 \\\\ \implies &x^2 - 2 x - 1 = 0 \\ \implies &\alpha = 1 - \sqrt{2}, \quad \beta = 1 + \sqrt{2}, \quad \alpha + \beta = 2, \quad \alpha \beta = -1 \end{aligned} {An+1−αAn=β(An−αAn−1)An+1−βAn=α(An−βAn−1)  ⟹  {An+1−αAn=βn(A1−αA0)=βn(3−α)An+1−βAn=αn(A1−βA0)=αn(3−β)  ⟹  (β−α)An=βn(3−α)−αn(3−β)\begin{aligned} &\begin{cases} A_{n+1} - \alpha A_n = \beta \left( A_n - \alpha A_{n-1} \right) \\ A_{n+1} - \beta A_n = \alpha \left( A_n - \beta A_{n-1} \right) \\ \end{cases} \\\\ \implies &\begin{cases} A_{n+1} - \alpha A_n = \beta^n \left( A_1 - \alpha A_0 \right) = \beta^n \left( 3 - \alpha \right) \\ A_{n+1} - \beta A_n = \alpha^n \left( A_1 - \beta A_0 \right) = \alpha^n \left( 3 - \beta \right) \\ \end{cases} \\\\ \implies &\left( \beta - \alpha \right) A_n = \beta^n \left( 3 - \alpha \right) - \alpha^n \left( 3 - \beta \right) \end{aligned}

Since α≠β\alpha \ne \beta, An=βn(3−α)−αn(3−β)β−α=βn(1+β)−αn(1+α)β−α=(1+2)n(2+2)−(1−2)n(2−2)22=(1+2)n(2+1)−(1−2)n(2−1)2=(1+2)n+1+(1−2)n+12(n≥1)\begin{aligned} A_n &= \frac{\beta^n \left( 3 - \alpha \right) - \alpha^n \left( 3 - \beta \right)}{\beta - \alpha} = \frac{\beta^n \left( 1 + \beta \right) - \alpha^n \left( 1 + \alpha \right)}{\beta - \alpha} \\\\ &= \frac{(1 + \sqrt{2})^n \left( 2 + \sqrt{2} \right) - (1 - \sqrt{2})^n \left( 2 - \sqrt{2} \right)}{2 \sqrt{2}} \\\\ &= \frac{(1 + \sqrt{2})^n \left( \sqrt{2} + 1 \right) - (1 - \sqrt{2})^n \left( \sqrt{2} - 1 \right)}{2} \\\\ &= \frac{(1 + \sqrt{2})^{n+1} + (1 - \sqrt{2})^{n+1}}{2} \quad (n \ge 1) \end{aligned}


© 2026. All rights reserved.