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 n2n \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 n1n - 1 letters.
    • So, An1A_{n - 1}.
  • (2) cc appears for the first time in the kk-th position where 2kn2 \le k \le n.
    • aa and bb must appear alternately up to the k1k-1-th time.
    • Excluding the first kk letters, the rest is equal to the number of cases to make a word with nkn - k letters.
    • So, 2Ank2 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=An1+2An2++2A0+2An1=An2+2An3++2A0+2AnAn1=An1+An2    An2An1An2=0    An+12AnAn1=0(n1)\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+12AnAn1=An+1(α+β)An+αβAn1=0    x22x1=0    α=12,β=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αAn1)An+1βAn=α(AnβAn1)    {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)(12)n(22)22=(1+2)n(2+1)(12)n(21)2=(1+2)n+1+(12)n+12(n1)\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}


© 2025. All rights reserved.