Please let me know if you can find any mistakes and explain corrections to my work.
This exercise is verbatim a Discrete Math professor's assignment.
Let $$W= \lbrace w \in \lbrace a, b, c \rbrace ^∗: |w| = 8 \rbrace $$ Find the number of words $w \in W$ with the following properties. You response should include a boxed numerical answer (use a calculator if needed) and justification for how you computed it. [ He then elaborates on what quality answers look like, mostly asking to explain your reasoning.]
(a) No two adjacent characters in w are the same.
(b) w contains at most 2 different characters.
(c) w contains at least 5 b's.
(d) w matches the regular expression $a^∗b^∗c^∗$.
(e) Every a in w is to the left of every c in w.
(f) w contains the subword “cab” (in consecutive positions).
My answers follow.
A. Number of choices for each position
$3 \cdot 2 \cdot 2 \cdot 2 \cdot 2 \cdot 2 \cdot 2 \cdot 2 = 3 \cdot 2^7$
B. Consider the alphabet $\lbrace d,e\rbrace$. Count of 8 letter permutations from this alphabet is $2^8$ There are $_{3}C_{2}$ combinations from a,b,c to d, e. So $2^8\cdot \space_{3}C_{2} = 768$
C. Let n = count of b's, $n \geq 5$ Most 2's below are from a choice of a or c.
n | Elaboration | Count |
---|---|---|
5 | (Count of locations for a,c) $\cdot 2^{8-n}$ See ** below. | $\space_{8}P_{5} \cdot 2^{8-5} $ |
6, 7, 8 | Similar, but use n | $\space_{8}P_{n} \cdot 2^{8-n} $ |
** This count is
(8 choices for 1st a or c) $\cdot$ (7 choices for 2nd a or c) $\cdot$ (6 choices for 3rd a or c)
$\cdot 2^{8-n}$ $\space_{8}P_{n} \cdot 2^{8-n} $
The sum is $$\sum_{i=5}^8 \space_{8}P_{i} \cdot 2^{8-i} = 2929$$
D. Essentially this is, where do we put the $a \to b$ transition, then where to put the $b \to c$ transition? I'll name the transition locations, $0.5, 1.5, \dots 8.5$ because they fall between letter positions, 1 to 8.
$$ \begin{array}{c c} a \to b & \text{count of $b \to c$ choices}\\ \hline 0.5 & 9\\ 1.5 & 8\\ 2.5 & 7\\ \vdots & \vdots\\ 8.5 & 1 \end{array} $$
$$\sum_{i=1}^9 i =45$$ I realize this can also be done with a stars and bars approach, but I'll study that more thoroughly later.
E. Essentially the alphabet is {ac, b} Let n = count of ac's.
$$ \begin{array}{c c c} n & \text{letters in the word} & \text{count}\\ \hline 4 & ac, ac, ac, ac & 1\\ 3 & ac, ac, ac, b, b & \dfrac{5!}{3!2!}\\ 2 & ac, ac, b, b, b, b & \dfrac{6!}{4!2!}\\ 1 & ac, b, b, b, b, b, b & \dfrac{7!}{6!1!}\\ 0 & b^8 & 1 \end{array} $$
The sum is $34$.
F. Consider one "cab", for example cab_ ____, with 6 choices for where to put cab and $3^5$ choices for the other letters.
However, this includes duplicates of cab as in "cab cab _ _".
$$ \begin{array}{c c} \text{first cab} & \text{first cab} \cdot \text{choices for second cab} \cdot \text{other letters} & \text{count}\\ cab \text{_____} & 1 \cdot 3 \cdot 3^2 & 27\\ \text{_} cab \text{___} & 1 \cdot 2 \cdot 3^2 & 18\\ \text{__} cab cab & 1 \cdot 1 \cdot 3^2 & 9 \end{array} $$
Count of words with two "cab"'s = $27 + 18 + 9 = 54$
[corrected previous $3^6$] (Count of one cab) minus (count of two cabs) is $3^5 \cdot 6- 54 = 1404$
Thankfully, there are at most two "cab"'s in an 8 letter word. Imagine the same question, but using "cac" instead of cab". This "cac", can overlap, as in "cacacac_" which has 3 "cac"'s.