Bernoulli Random Variables and Variance The question is:

Suppose $Z_1, Z_2, \ldots $ are iid $\operatorname{Bernoulli}\left(\frac{1}{2}\right)$ and let $S_n = Z_1 + \ldots +Z_n$. Let $T$ denote the smallest $n$ such that $S_n = 3$. Calculate $\operatorname{Var}(T)$.

What I know is that $\operatorname{Var}(T) = E(T^2) - E(T)^2$ but I am not sure how to calculate the expectation from the given information. Perhaps need to go through moment-generating function and the formula $M^{(r)}(0) = E(X^r)$?
 A: The moment generating function idea is in this case a good one. 
Let $T_1$ be the smallest $n$ such that $S_n=1$. More informally, $T_1$ is the waiting time until the first "success." Let $T_2$ be the waiting time from the first success to the second, and let $T_3$ be the waiting time from the second success to the third. 
Then the $T_i$ are independent and identically distributed, and $T=T_1+T_2+T_3$. Thus the moment generating function of $T$ is the cube of the mgf of $T_1$.
We proceed to find the mgf of $T_1$. So we want $E(
e^{tT_1})$. Note that $T_1=k$ with probablity $\frac{1}{2^k}$. So for the moment generating function of $T_1$ we want 
$$\sum_{k=1}^\infty \frac{1}{2^k}e^{tk},$$
This is an infinite geometric progression with first term $\frac{e^t}{2}$ and common ratio $\frac{e^t}{2}$. Thus the moment generating function of $T_1$ is
$$\frac{e^t}{2(1-\frac{e^t}{2})}.$$
Cube this to get the mgf of $T$, and use that mgf to find $E(T)$ and $E(T^2)$. 
Remark: The fact that the probabilities were $\frac{1}{2}$ was not of great importance. And neither was the fact that we are interested in the waiting time until the third success. 
Our $T$ has distribution which is a special case of the negative binomial. The method we used adapts readily to find the mgf of a general negative binomial.
A: You can compute the value of $\mathbb P(T=k)$ for each integer $k$. Since we deal with random variables which takes values either $0$ or $1$, the event $T=k$ is the same as $(S_{k-1}=2)\cap (Z_k=1)$. Now use independence, and what you know about the distribution of $S_n$ for $n\geqslant 1$.
A: $$
\begin{align}
& \phantom{{}=} \Pr(\min\{n : S_n=3\} = t) \\[8pt]
& = \Pr(\text{exactly 2 successes in }t-1\text{ trials and success on }t\text{th trial}) \\[8pt]
& = \Pr(\text{exactly 2 successes in }t-1\text{ trials})\cdot\Pr(\text{success on }t\text{th trial}) \\[8pt]
& = \left(\binom {t-1} 2 \left(\frac12\right)^{t-1}\right)\cdot\left(\frac12\right) \\[8pt]
& = \binom{t-1}{2} \left(\frac12\right)^t.
\end{align}
$$
So
$$
\begin{align}
\mathbb E(T) & = \sum_{t=3}^\infty t\cdot \binom{t-1}{2} \left(\frac12\right)^t = \sum_{t=3}^\infty 3\binom t3 \left(\frac12\right)^t \\[8pt]
& = \left.\sum_{t=3}^\infty 3\binom t3 p^t\right|_{p=1/2} \\[8pt]
& = \sum_{t=3}^\infty \frac12 p^3 \frac{d^3}{dp^3} p^t \\[8pt]
& = \frac12 p^3\frac{d^3}{dp^3}\sum_{t=3}^\infty p^t.
\end{align}
$$
Now sum the geometric series, differentiate, and then plug in $1/2$ for $p$.
$\mathbb E(T^2)$ can perhaps most easily be found by writing it as $\mathbb E(T(T-1)) + \mathbb E(T)$ and applying a method like that above to find the first expected value.
