Find the number of ways in which coin tosses can be made such that there are not three consecutive heads or tails.
actually I think THT TTH HHT HTH possibilities and the recursive relation but I dont know how can I express them ??
Find the number of ways in which coin tosses can be made such that there are not three consecutive heads or tails.
actually I think THT TTH HHT HTH possibilities and the recursive relation but I dont know how can I express them ??
Consider creating a string of H and T of length $k$ by adding one toss to the previous string of length $k-1$.
Let $P_k$ be the number of strings of length $k$ that contain no triplets and end in TH or HT.
Let $M_k$ be the number of strings of length $k$ that contain no triplets and end in TT or HH. Thus the number we desire is $N_k = P_k + M_k$.
But while either toss can be added to $P_{k-1}$ only one specific toss leads to a $P_k$ string; another toss leads to an $M_k$ string. And only one specific toss can be added to an $M_{k-1}$ string; it leades to a $P_k$ string. Thus
$$P_k = P_{k-1} + M_{k-1} \\ M_k = P_{k-1}$$
Then $$P_k = P_{k-1} + P_{k-2}$$
This is the equation determining the Fibonacci sequence; the starting conditions are that $P_2 = 2, P_3 = 6$. So
$$P_k = 2F_k$$ where $F_k$ is the $k$-th Fibonacci number. And then
$$ N_k = 2 F_{k+1}$$
The so-called Goulden-Jackson Cluster Method is a convenient technique to derive a generating function for problems of this kind.
We consider the set of binary words of length $n\geq 0$ and the set $B=\{HHH,TTT\}$ of bad words, which are not allowed to be part of the words we are looking for. We derive a generating function $f(s)$ with the coefficient of $s^n$ being the number of wanted words of length $n$.
According to the paper (p.7) from Goulden and Jackson the generating function $f(s)$ is \begin{align*} f(s)=\frac{1}{1-ds-\text{weight}(\mathcal{C})}\tag{1} \end{align*} with $d=|\mathcal{V}|=2$, the size of the alphabet and with the weight-numerator $\mathcal{C}$ with \begin{align*} \text{weight}(\mathcal{C})=\text{weight}(\mathcal{C}[HHH])+\text{weight}(\mathcal{C}[TTT]) \end{align*} We calculate according to the paper \begin{align*} \text{weight}(\mathcal{C}[HHH])&=\text{weight}(\mathcal{C}[TTT])\\ &=-\frac{s^3}{1+s+s^2}=-\frac{s^3(1-s)}{1-s^3}\\ \end{align*}
and
we obtain the generating function $f(s)$ for the binary words which do not contain the bad words \begin{align*} f(s)&=\frac{1}{1-2s+\frac{2s^3(1-s)}{1-s^3}}\\ &=\frac{2}{1-s-s^2}-1\\ &=1+2s+4s^2+6s^3+10s^4+16s^5+26s^6+42s^7+\cdots \end{align*}
Note, the result is essentially twice the generating function of the Fibonacci numbers \begin{align*} \frac{1}{1-s-s^2} \end{align*}
The DFA method (which is the naive approach) will produce the following transcript, matching the answer by @MarkusScheuer.
> GFNC([[0,0,0],[1,1,1]], 2, true); [[1, 1, 1], [0, 0, 0]] Q[], 0, Q[0] Q[], 1, Q[1] Q[0], 0, Q[0, 0] Q[0], 1, Q[1] Q[0, 0], 0, Q[0, 0, 0] Q[0, 0], 1, Q[1] Q[0, 0, 0], 0, Q[0, 0, 0] Q[0, 0, 0], 1, Q[0, 0, 0] Q[1], 0, Q[0] Q[1], 1, Q[1, 1] Q[1, 1], 0, Q[0] Q[1, 1], 1, Q[1, 1, 1] Q[1, 1, 1], 0, Q[1, 1, 1] Q[1, 1, 1], 1, Q[1, 1, 1] 2 z + z + 1 - ---------- 2 z + z - 1 > series(%, z=0, 9); 2 3 4 5 6 7 8 9 1 + 2 z + 4 z + 6 z + 10 z + 16 z + 26 z + 42 z + 68 z + O(z )
We can also derive this from first principles, getting the generating function (use $z$ for heads and $w$ for tails):
$$f(z,w) = (1+z+z^2) \left(\sum_{q\ge 0} (w+w^2)^q (z+z^2)^q\right) (1+w+w^2).$$
This simplifies to
$$(1+z+z^2) \frac{1}{1-w(w+1)z(z+1)} (1+w+w^2).$$
Now we are only interested in the count, so we may drop the distinction between heads amd tails to get
$$\frac{(1+z+z^2)^2}{1-z^2(1+z)^2} = \frac{(1+z+z^2)^2}{(1+z(1+z))(1-z(1+z))} = \frac{1+z+z^2}{1-z-z^2}.$$
This is the same generating function as before.
this is easy using recursion, suppose $f_n$ is the desired number. We have $f_1=2,f_2=4$. And for $n> 2$ we have:
The desired sequences of length $n$ can be separated into $2$ types:
The ones in which the last two flips are different ( there are $f_{n-1}$ of this type).
The ones in which the last three flips are all the same ( there are $f_{n-3}$ of this type).
We hence have the recursion $f_n=f_{n-1}+f_{n-2}$