Independent trials, each resulting in a success with probability p, are performed in sequence. Let N be the trial number of the first success. Find Var(N).
Let Y = 1 if the first trial results in a success, and Y = 0 otherwise.
\operatorname{Var}(N)=E[N^{2}]-(E[N])^{2}To calculate E[N^{2}]{\mathrm{~and~}}E[N] we condition on Y. For instance,
E[N^{2}]=E[E[N^{2}|Y]]However,
E[N^{2}|Y=1]=1,E[N^{2}|Y=0]=E[(1+N)^{2}]
These two equations are true since if the first trial results in a success, then clearly N = 1 and so N^{2} = 1. On the other hand, if the first trial results in a failure, then the total number of trials necessary for the first success will equal one (the first trial that results in failure) plus the necessary number of additional trials. Since this latter quantity has the same distribution as N, we get that E[N^{2}|Y=0]=E[(1+N)^{2}]. Hence, we see that
E[N^{2}]=E[N^{2}|Y=1]P\{Y=1\}+E[N^{2}|Y=0]P\{Y=0\}=p+E[(1+N)^{2}](1-p)
=1+(1-p)E[2N+N^{2}]
Since, as was shown in Example 3.11, E[N] = 1/p, this yields
E[N^{2}]=1+{\frac{2(1-p)}{p}}+(1-p)E[N^{2}]or
E[N^{2}]={\frac{2-p}{p^{2}}}Therefore,
\operatorname{Var}(N)=E[N^{2}]-(E[N])^{2}={\frac{2-p}{p^{2}}}-\left({\frac{1}{p}}\right)^{2}
={\frac{1-p}{p^{2}}}