Number of $n$ length word that can be formed using the alphabets $a$, $b$, $c$, $d$ such that $a$ and $b$ never come together. My thought : Total $n$ letter words that can be formed by repeating $4$ letters is number of onto functions from set of $n$ elements to set of $4$ elements.
This is equal to $4^n-4\times 3^n+6\times 2^n-4$. But I cannot count how many times a and b will come together. Please help.
 A: Assuming you don’t have to use all the letters, then let $A_n$ be the number of such words that end in $a$ or $b,$ and $C_n$ be the words that don’t. Then $A_0=0,C_0=1,$ and $$A_{n+1}=A_n+2C_{n}\\C_{n+1}=2A_n+2C_n$$
Or:
$$\begin{pmatrix}A_n\\C_n\end{pmatrix}=\begin{pmatrix}1&2\\2&2\end{pmatrix}^n\begin{pmatrix}0\\1\end{pmatrix}$$
The number you want is $D_n=A_n+C_n.$ You can get a closed formula by diagonalizing the matrix, or by representing the $(0,1)^T$ as a sum of eigenvectors of the matrix.
You can get a linear recurrence:
$$D_{n+1}=3D_n+2D_{n-1}, D_0=1,D_1=4$$
You can find a direct argument for that recurrence.
The exact answer I get is:
$$D_n=\frac{17+5\sqrt{17}}{34}\left(\frac{3+\sqrt{17}}2\right)^n+
\frac{17-5\sqrt{17}}{34}\left(\frac{3-\sqrt{17}}2\right)^n$$
Which can also be written as the nearest integer to: $$\frac{17+5\sqrt{17}}{34}\left(\frac{3+\sqrt{17}}2\right)^n\approx 1.106\cdot 3.562^n$$
If you really must use all the letters, you’ll need to add this sort of computation to an inclusion-exclusion argument. You’ll have to use a similar argument for subtracting the case when one of $c$ or $d$ is not in the string.
A: I agree with Calvin Lin's comment.  That is, the starter enumeration is $4^n$.
Also, I reject the Inclusion-Exclusion approach as being to unwieldy, given that a formula is required for the generic value of $n$.  For a small explicit value of $n$, I would have more strongly considered Inclusion-Exclusion.
Highjacking the insight from the comment of Thomas Andrews, I will use recursion.
For $n=2$, the number of satisfying words is $(4^2) - 2.$ 
To investigate the use of recursion, I must enumerate how many of the $(14)$ satisfying $2$-letter words end in $a$ or $b$, and how many do not.
If the last character is $a$ or $b$, then, in the satisfying word, there are 3 choices for the first character.  Therefore, there are $6$ satisfying $2$-letter words that end in $a$ or $b$.  Similarly, if the last character is $c$ or $d$, then the first character is unconstrained.  Therefore, there are $8$ satisfying $2$-letter words that end in $c$ or $d$.
Let $T_n$ denote the number of satisfying words of length $n$. 
Let $S_n$ denote the number of satisfying words of length $n$ that end in either $a$ or $b$. 
Let $R_n$ denote the number of satisfying words of length $n$ that end in either $c$ or $d$.
Then, in general, you have that $R_n + S_n = T_n$.
In particular, you have that $R_2, S_2, T_2 = 8, 6, 14,$ respectively.
The challenge is to find the formulas for $R_{n+1}, S_{n+1}, T_{n+1}$ in terms of $R_n, S_n, T_n$.
My approach is to enumerate $R_3, S_3, T_3$, and then use this to derive the necessary formulas.
The $(R_2 = 8)$ two-letter words can be followed either by one of $a,b$ or not.
Therefore, a starter-running-total for the enumeration of $R_3, S_3$ is $R_3 = 2 \times R_2, ~~S_3 = 2 \times R_2$.
The $(S_2 = 6)$ two-letter words can either be followed by $c,d$ or by the $(a,b)$ letter that matches the 2nd letter used.
Therefore, the incremental addition to $R_3, S_3$ generated by extending the $6$ two-letter words is $R_3 = R_3 + (2 \times S_2), ~~ S_3 = S_3 + S_2$
Putting this all together, this implies that:

*

*$R_3 = (2R_2) + (2S_2) = 2T_2$.

*$S_3 = (2R_2) + S_2 = 2T_2 - S_2.$

*$T_3 = (2T_2) + (2T_2 - S_2) = 4T_2 - S_2$.


The nice thing about the above analysis, is that it is independent of $n$.
So, in general:

*

*$S_{n+1} = 2T_n - S_n$

*$T_{n+1} = 4T_n - S_n$.

Based on the above formulas, you can immediately generate the following chart:
\begin{array}{| r | r | r |}
  \hline                       
  n & S_n & T_n \\
  \hline                       
  2 & 6 & 14 \\
\hline
  3 & 22 & 50 \\
\hline
  4 & 78 & 178 \\
\hline
  5 & 278 & 634 \\
  \hline  
\end{array}

Addendum
A very good case can be made that my answer is incomplete.  That is, what is really desired is a closed form expression.  Although I was not able to generate such an expression, I can at least demonstrate the attempt that I made.
$S_{n+1} = 2T_n - S_n.$ 
$T_{n+1} = 4T_n - S_n.$
This leads to 
$S_{n+2} = 6T_n - S_n.$ 
$T_{n+2} = 14T_n - 3S_n.$
This leads to 
$S_{n+3} = 22T_n - 5S_n.$ 
$T_{n+3} = 50T_n - 11S_n.$
Personally, I was not able to find an elegant algebraic expression for $S_{n+k}, T_{n+k}$ in terms of $k$.  If I had been able to, I would have then plugged in the values of $S_2, T_2 = 6, 14.$
