help verifying answer to inclusion/exclusion on strings example

85 Views Asked by At

So I'm trying to learn inclusion/exclusion but am having a hard time understanding this example.

How many strings of length 6 over the alphabet ${A, B, C}$ start with a $C$ or end with a $C$?

So I understand there are $3^5$ strings of length $6$ that start with C, and also $3^5$ strings of length $6$ that end with C. However I'm not understanding the intersection part. What does it mean to get the intersection of those $2$ values? The example shows $C * * * * C$, so I'm assuming this means we can pick 4 more letters out of ${A, B, C}$, so $3^4$?

And the answer to the problem is $3^5 + 3^5 - 3^4 = 405$?

I tried looking at other problems posted but it just adds to my confusion.

2

There are 2 best solutions below

0
On BEST ANSWER

You are correct, there are $3^5$ strings that start with a $C$ and there are $3^5$ that end on a $C$. However, adding all those up, we counted some strings twice, namely all strings that start and end in a $C$. We need to subtract these doubly counted strings. There $3^4$ strings that start with and end in a $C$ so the answer is indeed $3^5 +3^5 -3^4$. If we do not subtract the $3^4$ strings, we would have double counted for instance $CAAAAC$.

0
On

All the wanted strings have one of the following structures:

  1. $(C)(\text{whatever})(\text{not}\,C)$
  2. $(\text{not}\,C)(\text{whatever})(C)$
  3. $(C)(\text{whatever})(C)$

There are $3^4\cdot 2$ strings of Type-1, $3^4\cdot 2$ strings of Type-2 and $3^4$ strings of Type-3.
So the answer is $5\cdot 3^4=405$.

Alternative approach: pick the first and the last character. Unless both these characters are elements of $\{A,B\}$ ($4$ chances) the whole string meets the wanted contraints. So there are $(3^2-2^2)\cdot 3^4=405$ solutions.