Why is the conditional expectation failed case written this way? This is my first post and I apologize in advance if I'm not using the right formatting/approach.
Problem
A coin, having probability $p$ of landing heads, is continually flipped until at least one head and one tail have been flipped.
Find the expected number of flips needed.
typical examples: “HT”, X = 2; “TTTTH”, X = 5.
Solution Begin
Denote X: # of flips needed. Y: outcome of 1st flip.
$$\operatorname E[X] = \operatorname E[X\mid Y = H]P(Y = H) + \operatorname E[X\mid Y = T]P(Y = T)$$
$$E[X\mid Y = H] = 1 + \operatorname E[\text{additional flips needed}] = 1 + \frac1{1-p}$$
Question
This is regarding $$1 + \frac1{1-p}$$
I understand that $1$ is for the failed trial but why is the $1/(1-p)$ there? Given the conditional probability/expectation, I thought the denominator would be the $P(Y=H)$ which is $p.$ I just don't understand the overall reason for $1/(1-p).$ Could someone help me understand or point me in the right direction?
 A: No, there is a misunderstanding. The quantity $E(X|Y=H)$ is not evaluated by using any law of conditional expectation. It is evaluated by seeing what the random variable $(X | Y = H)$ is. That is, once $Y=H$, what is the distribution of $X$.
The answer to that is that $X$ is (one more than, to count for the first flip) the number of flips to wait for a tail : so we flip till we get a tail , which happens with probability $1-p$. This is the description of a geometric random variable (plus $1$), with success probability $1-p$.
Thus, $X | Y=H \sim 1+\mbox{Geom}(1-p)$, and therefore $$E(X | Y = H) = 1+ E[\mbox{Geom}(1-p)] =  1 + \frac 1{1-p}$$
Since the geometric distribution with success probability $q$ has expectation $\frac 1q$. Note that similar arguments provide for the distribution of $X|Y=T$  and the quantity $E(X|Y=T)$.
A: $\mathsf E(X\mid Y{=}H)$ will equal the expected count of flips until at least one tail and one head occur, when given the first flip is a head.  This will be $1$ plus the expected count for flips until a tail is seen after the first flip.
The count for flips until a tail is seen, is a Geometric Distributed Random variable with rate parameter $(1-p)$ : that is the success rate for obtaining a tail.
Thus $$\begin{align}\mathsf E(X)& = p\,\mathsf E(X\mid Y{=}H)+(1-p)\,\mathsf E(X\mid Y{=}T)\\&= p\,(1+(1-p)^{-1})+(1-p)\,(1+p^{-1})\end{align}$$
