Q:

Finding the expected number of flips needed for a coin having probability $p$ of landing on heads

A coin, having probability $p$ of landing on heads and probability of $q=1-p$ of landing on tails.  It is continuously flipped until at least one head and one tail have been flipped. 
  a) Find the expected number of flips needed. 

This is not part of a homework assignment.  I am studying for a final and don't understand the professors solutions.  Since this is clearly geometric, I would think the solution would be:
$$E(N)=\sum_{i=0}^{\infty}ip^{n-1}q+\sum_{i=0}^{\infty}iq^{n-1}p=\frac{1}{q}+\frac{1}{p}.$$
However, I am completely wrong.  The answer is
$$E(N)=p\left(1+\frac{1}{q}\right)+q\left(1+\frac{1}{p}\right).$$
For example, consider we flip for heads first.  Then we have
$$E(N\mid H)=p+p\sum_{i=0}^{\infty}np^{n-1}q.$$
I am not sure why this makes sense.  I am not entirely sure why we have an added $1$ and a factored $p$, $q$. Could someone carefully explain why it makes sense that this is the right answer? 

A:

If you get a head with probability $p$ then the expected number of throws is $1+E(X)$ where $X$ is a geometric distribution requiring a tail to be thrown with probability $q$ so $1+E(X)=1+\frac1q$. Similarly if you throw a tail with probability $q$ then the expected number of throws is $1+E(Y)$ where $Y$ is a geometric distribution requiring a head to be thrown with probability $p$ so $1+E(Y)=1+\frac1p$. This means that the overall expected number of throws is
$$p\left(1+\frac1q\right)+q\left(1+\frac1p\right)$$
because there is a probability $p$ that the expected number of throws is given by $1+E(X)$ and probability $q$ that it is given by $1+E(Y)$.

