Finding $E[X]$, $\operatorname{Var}(X)$ and distribution of $X$ in Bernoulli trials Let $X$ be the number of Bernoulli ($p$) trials required to produce at least one success and at least one failure. What is the distribution of $X$? Also, what is $E[X]$ and $\operatorname{Var}(X)$?
To find $\operatorname{Var} (X)$ I know that I'll need to use the formula $E\left[X^2\right]-\left(E\left[X\right]\right)^2$ after I find $E[X]$ and also $E\left[X^2\right]$. How would I do that? I think that $X$ has a geometric distribution, but how do I show that?
 A: Let's try some values, letting $H$ = heads = success and $T$ = tails = failure:
\begin{align*}
P(X = 1) & = 0, \\
P(X = 2) & = P(HT \text{ or } TH) = p(1-p) + (1-p)p, \\
P(X = 3) & = P(HHT \text{ or } TTH) = p^2(1-p) + (1-p)^2p, \\
P(X = 4) & = P(HHHT \text{ or } TTTH) = p^3(1-p) + (1-p)^3p, \\
& \vdots
\end{align*}
So we can see that 
$$
P(X = n) = 
\begin{cases}
0, \qquad &  n = 1, \\
p^{n-1}(1-p) +(1-p)^{n-1}p, \qquad & n \geq 2
\end{cases}
$$
and we have the pmf.  You can calculate expected value based on the observation that
$$
P(X = n) = P(Y_1 = n) + P(Y_2 = n)
$$
where $Y_1 \sim geom(p)$ and $Y_2 \sim geom(1-p)$ for $n \geq 2$.  Recall that $E(Y_1) = \frac{1}{p}$ and $E(Y_2) = \frac{1}{1-p}$.  Then
\begin{align*}
E(X) & = \sum_{n=2}^\infty n \left[p^{n-1}(1-p) +(1-p)^{n-1}p\right] \\
& = \sum_{n=2}^\infty n p^{n-1}(1-p) + \sum_{n=2}^\infty n(1-p)^{n-1}p \\
& = \underbrace{\sum_{n=1}^\infty n p^{n-1}(1-p)}_{E(Y_2)} - (1-p) + \underbrace{\sum_{n=1}^\infty n(1-p)^{n-1}p}_{E(Y_1)} - p \\
& = \frac{1}{1-p} - (1-p) + \frac{1}{p} - p
\end{align*}
Similarly for variances.
