A coin comes up heads with probability $p$ and tails with probability $q = 1 - p$. For the moment, assume that $p$ is a constant.
a. [3 points] Prove the expected number of coin flips needed to produce the pattern HT for the very first time is $\frac{1}{p} + \frac{1}{q}$.
Hint: TTTTTH|HHHHHHHT requires 14 flips to generate the pattern HT. The TTTTTH part before the | produces the first H, and the HHHHHHHT part after the | produces the first T after that first H.
b. [6 points] Prove that the expected number of coin flips needed to produce the pattern HH for the first time is $\frac{1}{p} + \frac{1}{p^2}$.
Hint: Define a random variable $X$ to track the number of flips needed to produce the pattern HH for the very first time, and use the Law of Total Expectation:
$E[X] = E[X|\text{last flip produced H}]p + E[X|\text{last flip produced T}]q$
c. [6 points] Now assume $p$ is no longer a constant but rather a random variable that behaves as $p \sim \text{Beta}(4, 7)$? What's the expected number of flips for part b now?
Recall that $B(a, b)$ is the normalization constant in place so that $\text{Beta}(a, b)$ is a valid random variable with a valid pdf.
$B(a, b) = \int_0^1 p^{a-1}(1 - p)^{b-1}dp$
This expression for $B(a, b)$ will be useful as you compute values for $E[\frac{1}{p}]$ and $E[\frac{1}{p^2}]$, which you'll need to compute your final answer here. In fact, you should express your final answer as a sum of fractions involving several $B(a, b)$ constants with different values of $a$ and $b$.