This is going to be a long one. Let’s start.
Definition – $\bf{X}$ :- This is a random variable which denotes the number of tosses required to get two consecutive tosses with the same outcome.
$P(X=1) = 0$ . This is because we need atleast two tosses to get two consecutive tosses.
$(P(X=2)=$ {$H,H$} or {$T,T$} = $\frac{1}{2}$
Notice that for any sequence of coin tosses, if the last two outcomes are {$T,T$} or {$H,H$} then $\exists$ only one valid sequence for the preceding part of it. Hence for every value of $X$, there are only two valid sequences.
For example if ($X=5$) and the last two outcomes are the same, then the possibilities are : $\color{red}{xxx}TT$ and $\color{red}{xxx}HH$
There is only possibility for $\color{red}{xxx}$ for each of the outcomes, which are $\color{red}{HTH}TT$ and $\color{red}{THT}HH$ respectively. Otherwise, we’d get a smaller sequence with same outcomes which refutes our definition of $X$.
Therefore $P(X=n)=\frac{2}{2^n}=\frac{1}{2^{n-1}}$ …. $\bf{(i)} $ for $ n \geq 2 $
We know, $\bf{E[X]}= \sum_{x} x \times p(x)$
Let us denote $\bf{E[X]}$ by S.
$ S= P(X=1) \times 1 + P(X=2) \times 2+ …… $to $\infty$
$S= 0+ 2 \times \frac{1}{2^1} + 3 \times \frac{1}{2^2} + 4 \times \frac{1}{2^3}… $ to $\infty$ – $\bf(iii)$
$2S= 0+ 2 \times \frac{1}{2^1} \times 2 + 3 \times \frac{1}{2^2} \times 2 + 4 \times \frac{1}{2^3} \times 2… $ to $\infty$ -$(\bf{iv})$
Subtracting $\bf{(iv)}$ from $\bf({iii})$ we have :
$S= 2 + \frac{1}{2}+ (3-2)\frac{1}{2^2}+ (4-3)\frac{1}{2^3}+ \frac{1}{2^4} ….$ to $\infty$
$S= 2 + \frac{\frac{1}{2}}{1-\frac{1}{2}}=2+1=3$
Hence, the expected value $\bf{E[X]}$=3.