[Math] How many strings of length 8

combinatoricsdiscrete mathematics

The question – how many strings of length 8, from 4 letter alphabet, using each letter twice. There is to be exactly one pair of same letters next to each other (example of valid string: AABCDBCD).

I tried to check how this develops by drawing a tree, but it seems that this gets really unwieldy really fast. What counting technique can be used here to make it easier?

Best Answer

Outline: Use Inclusion/Exclusion. Count first the number of words with a double A. It is perhaps easy to see that there are $\frac{7!}{2!2!2!}$ such words. Similarly, there are $\frac{7!}{2!2!2!}$ with a double B, and so on. So our first estimate is that there are $4\cdot \frac{7!}{2!2!2!}$ words of the desired kind.

However, this double-counts the number of words with, for example, a double A and a double B. There are $\frac{6!}{2!2!}$ such words. There are $\binom{4}{2}$ ways to choose the pair that we will have two doubles of. So our next estimate of the required number of words is $4\cdot \frac{7!}{2!2!2!}-\binom{4}{2}\cdot \frac{6!}{2!2!}$.

However, we have subtracted too much, for we have subtracted one too many times the $\binom{4}{3}\cdot \frac{5!}{2!}$ words of that have three doubles.

After we have added back $\binom{4}{3}\cdot \frac{5!}{2!}$, there is only a little adjustment left to make.

Related Question