My attempt:
Let $H$ be the outcome heads, and $T$ be tails. Let $X$ be the random variable "number of tosses required to get 3 consecutive heads". The minimum number of trials (tosses) is 3. Thus we have infinite sample space:
$$\{HHH, THHH, TTHHH, HTHHH, TTTHHH, THTHHH, HTTHHH, HHTHHH,....\}$$
For the first 2 elements of sample space, we have the probabilities $(1/2)^{3}$ and $(1/2)^{4}$ respectively. Then we have 2 ways to get 3 consecutive heads out of 5 tosses, hence the probability is $2(1/2)^{5}$. Similar for 4th, 5th and 6th tosses. For $n = 7, 8, 9,... \infty$ tosses, we have
$$2^{n-4} - \frac{(n-5)(n-6)}{2}$$ ways of getting 3 consecutive heads.
Thus the expectation is
$$E(X) = 3(1/2)^{3} + 4(1/2)^{4} + 5 \cdot 2 (1/2)^{5} + 6 \cdot 4(1/2)^{6} + \sum_{n=7}^{\infty} \frac{n}{2^{n}}\left(2^{n-4} - \frac{(n-5)(n-6)}{2}\right) $$
However the infinite sum above doesn't converge, so obviously the approach is wrong.
I have looked at related posts (i.e. Expected Number of Coin Tosses to Get Five Consecutive Heads) but I don't see how my approach fails.
Edit: computation of $$2^{n-4} - \frac{(n-5)(n-6)}{2}, \qquad n \geq 7.$$
I need to compute the number of ways that X -values can be next to each other for a given number of tosses $n \geq 7$. For this $n$, I have a sample space element of the form $...TXXX$, consisting of $n$ symbols $T$ and $H$. Thus, I have a choice of $2^{n-4}$ arrangements for the first $n-4$ symbols. Out of those, I need to exclude the sequences of symbols of the form $XXX...X$, for 3 or more values of $X$. There are $(n-6)$ such arrangements for 3 consecutive $X$ values, $(n-7)$ arrangements for 4 consecutive $X$s, $(n-8)$ arrangements for 5 $X$s, and so on. Hence for the total of such arrangements, we have the arithmetic progression
$$n-6, n-7, n-8,...0.$$ For a given $n$, the sum turns out to be $$\frac{(n-5)(n-6)}{2}$$ Hence, we have the result $2^{n-4} - \frac{(n-5)(n-6)}{2}$ as stated above...