<s>[INST] Calculate $E(X)$ and the PMF of Number of Flips to Get $2$ Consecutive Heads or Tails with a Coin Flips Consider flipping a fair coin until either two consecutive heads appear or two consecutive tails appear, and let $X$ denote the total number of flips required to obtain the $2nd$ consecutive heads or the $2nd$ consecutive tails.
(a) Give the $pmf$ of $X$. 
(b) Give the value of $E(X)$. 
Attempted Solution:
(a) We need to have a sequence of tosses of length $n-1$ of the form HTHTHT,..., or THTHTH,..., and the probability that each sequence happens for $n - 1$ tosses is $\frac{1}{2^{n-1}}$. So the total probability of the two sequences is $\frac{2}{2^{n-1}}$. But then the next toss must be the same as the $(n-1)$th toss giving 
$$\frac{2}{2^{n-1}}\frac{1}{2} = \frac{1}{2^{n-1}}.$$
I have then that $P(X=n)$ = $\frac{1}{2^{n-1}}$ where $n \geq 2$ so the $pmf$ would be
$$p_X(n) = \begin{cases} {\frac{1}{2^{n-1}}} & \text{$n \geq 2$}  \\  
{0} & \text{otherwise}\end{cases}$$
(b) Then would the $E(X)$ just be $\sum_2^\infty{\frac{n}{2^{n-1}}} = 3$?
 [/INST] The Probability Mass Function (PMF)
Let $ X $ be the random variable that counts the number of tosses until we get two successive tosses of the same type. 
We're basically dealing with Binary Chains which each chain has the probability of $ \frac{1}{ {2}^{n} } $ where $ n $ is the length of the chain.
The probability $ P \left( X = n \right) $ means having $ n - 1 $ chain of alternating tails and heads (HTHTHTH or THTHTHT for $ n = 7 $). Since there are 2 of those (One starts with H the other with T) their probability is $ \frac{2}{ {2}^{n} } $. The probability to have in the $ n $ -th toss H or T as required is $ \frac{1}{2} $ hence the Probability Mass Function is given by:
$$ {P}_{X} \left( n \right) = \begin{cases}
\frac{1}{ {2}^{n - 1} } & n \geq 2 \\
0 & n \leq 1
\end{cases} $$
The Expected Value
Solution 001
By definition the expected value is given by:
$$ \mathbb{E} \left[ X \right] = \sum_{n = 2}^{\infty} n {P}_{X} \left( n \right) = \sum_{n = 2}^{\infty} \frac{n}{ {2}^{n - 1}} = \sum_{n = 1}^{\infty} \frac{n + 1}{ {2}^{n} } = \sum_{n = 1}^{\infty} \frac{1}{ {2}^{n} } + \sum_{n = 1}^{\infty} \frac{n}{ {2}^{n} } $$
Now, the first term $ \sum_{n = 1}^{\infty} \frac{1}{ {2}^{n} } $ is  a geometric series and it is known that $ \sum_{n = 1}^{\infty} \frac{1}{ {2}^{n} } = 1 $.
Looking at the second term:
$$ {S} = \sum_{n = 1}^{\infty} \frac{n}{ {2}^{n} } \Rightarrow \frac{S}{2} = \frac{1}{2} \sum_{n = 1}^{\infty} \frac{n}{ {2}^{n} } = \sum_{n = 1}^{\infty} \frac{n}{ {2}^{n + 1} } = \sum_{n = 1}^{\infty} \frac{n - 1}{ {2}^{n} } $$
Now one could use another trick:
$$ \begin{align*}
\frac{S}{2} & = S - \frac{S}{2} \\
& = \sum_{n = 1}^{\infty} \frac{n}{ {2}^{n} } - \sum_{n = 1}^{\infty} \frac{n - 1}{ {2}^{n} } \\
& = \sum_{n = 1}^{\infty} \left( \frac{n}{ {2}^{n} } - \frac{n - 1}{ {2}^{n} } \right) \\
& = \sum_{n = 1}^{\infty} \frac{1}{ {2}^{n} } = 1 \\
& \Rightarrow S = 2
\end{align*} $$
Which implies $ \mathbb{E} \left[ X \right] = \sum_{n = 1}^{\infty} \frac{1}{ {2}^{n} } + \sum_{n = 1}^{\infty} \frac{n}{ {2}^{n} } = 1 + 2 = 3 $.
Solution 002
By examining the term $ P \left( X \geq n \right) $:
$$ \begin{array} \\
P \left( X \geq 1 \right) & = & P \left( X = 1 \right)  & + & P \left( X = 2 \right)  & + & P \left( X = 3 \right) + \cdots \\
P \left( X \geq 2 \right) & = &            &   & P \left( X = 2 \right)  & + & P \left( X = 3 \right) + \cdots \\
P \left( X \geq 3 \right) & = &            &   &             &   & P \left( X = 3 \right) + \cdots \\
\end{array} $$
One could see (Summing along the columns) that:
$$ \sum_{n = 1}^{\infty} P \left( X \geq n \right) = 1 P \left( X = 1 \right) + 2 P \left( X = 2 \right) + 3 P \left( X = 3 \right) + \cdots + n P \left( X = n \right) = \mathbb{E} \left[ X \right] $$
The term $ P \left( X \geq n \right) $ is the event of having $ n - 1 $ alternating chain as above. Namely:
$$ P \left( X \geq n \right) = \begin{cases}
\frac{1}{ {2}^{n - 2} } & n \geq 2 \\
1 & n \leq 1
\end{cases} $$
This implies:
$$ \mathbb{E} \left[ X \right] = \sum_{n = 1}^{\infty} P \left( X \geq n \right) = 1 + 1 + \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \ldots = 3 $$ 
</s>