Question:
Let $\sigma=\{a,b,c\}$. How many words can we assemble without the substrings $'ab'$ and $'bc'$?
- define the recursive formula.
- define the generating function for this formula.
$Solution.A.$
For the first sub-question, we consider 3 disjoint cases: $$a_{n}^{c}=\text{the number of valid words with length of $n$, starting with 'c' }$$ $$a_{n}^{b}=\text{the number of valid words with length of $n$, starting with 'b' }$$ $$a_{n}^{a}=\text{the number of valid words with length of $n$, starting with 'a' }$$
For the first case, we can add $'c'$ at the beginning of the word and then take a valid word with a length of $n-1$. Therefore, we have $a_{n-1}$ options for this case.
For the second case, we use the complement method. We can take all valid words starting with $'b'$ and then get rid of all the options for words with a length of $n-2$ starting with $'c'$. So we have: $a^{b}_{n}=a_{n-1}-a_{n-2}$ options.
For the third case, we use the complement method. We can take all valid words starting with $'a'$ and then get rid of all the options for words with a length of $n-2$ starting with $'b'$. So we have: $$a_{n}^{a} =a_{n-1} -a_{n-1}^{b} =a_{n-1} -( a_{n-2} -a_{n-3}) =a_{n-1} -a_{n-2} +a_{n-3}$$ options.
Now, since all three cases are disjoint then it is clear that: $a_{n} =a_{n}^{a} +a_{n}^{b} +a_{n}^{c}$, so therefore,$$a_{n} =a_{n}^{a} +a_{n}^{b} +a_{n}^{c} =a_{n-1} +a_{n-1} -a_{n-2} +a_{n-1} -a_{n-2} +a_{n-3}\\ =3a_{n-1} -2a_{n-2} +a_{n-3}$$
$Solution.B.$
Let $$F( x) =\sum _{n=0}^{\infty } a_{n} x^{n}$$
Thus,$$ \begin{array}{l} F( x) =\sum _{n=0}^{\infty } a_{n} x^{n} =a_{0} +a_{1} x+a_{2} x^{2} +\sum _{n=3}^{\infty }( 3a_{n-1} -2a_{n-2} +a_{n-3}) x^{n}\\ \\ =1+3x+7x^{2} +\sum _{n=3}^{\infty }( 3a_{n-1} -2a_{n-2} +a_{n-3}) x^{n}\\ \\ =1+3x+7x^{2} +3\sum _{n=3}^{\infty } a_{n-1} x^{n} -2\sum _{n=3}^{\infty } a_{n-2} x^{n} +\sum _{n=3}^{\infty } a_{n-3} x^{n}\\ \\ =1+3x+7x^{2} +3x\underbrace{\sum _{n=3}^{\infty } a_{n-1} x^{n-1}}_{F( x) \ -\ a_{1} x\ -\ a_{0}} -2x^{2}\underbrace{\sum _{n=3}^{\infty } a_{n-2} x^{n-2}}_{F( x) \ -\ a_{0}} +x^{3}\underbrace{\sum _{n=3}^{\infty } a_{n-3} x^{n-3}}_{F( x)}\\ \\ =1+3x+7x^{2} +3x( F( x) -a_{1} x-a_{0}) -2x^{2}( F( x) -a_{0}) +x^{3} F( x)\\ \\ =1+3x+7x^{2} +3x( F( x) -3x-1) -2x^{2}( F( x) -1) +x^{3} F( x)\\ \\ =1+3x+7x^{2} +3xF( x) -9x^{2} -3x-2x^{2} F( x) +2x^{2} +x^{3} F( x)\\ \\ =1+\left( 3x-2x^{2} +x^{3}\right) F( x) \end{array}$$
therefore, we have that: $$ \begin{array}{l} F( x) =1+\left( 3x-2x^{2} +x^{3}\right) F( x) /-\left( 3x-2x^{2} +x^{3}\right) F( x)\\ \\ F( x) -\left( 3x-2x^{2} +x^{3}\right) F( x) =1\\ \\ \left( 1-\left( 3x-2x^{2} +x^{3}\right)\right) F( x) =1\\ \\ \left( 1-3x+2x^{2} -x^{3}\right) F( x) =1/:\left( 1-3x+2x^{2} -x^{3}\right)\\ \\ \boxed{F( x) =\frac{1}{1-3x+2x^{2} -x^{3}}} \end{array}$$
Now, is it correct?