Independent trials, each of which is a success with probability p, are performed until there are k consecutive successes. What is themean number of necessary trials?
Let N_{k} denote the number of necessary trials to obtain k consecutive successes, and let M_{k} denote its mean. We will obtain a recursive equation for M_k by conditioning on N_{k−1,} the number of trials needed for k −1 consecutive successes. This yields
M_k=E\left[N_k\right]=E\left[E\left[N_k \mid N_{k-1}\right]\right]
Now,
E\left[N_k \mid N_{k-1}\right]=N_{k-1}+1+(1-p) E\left[N_k\right]
where the preceding follows since if it takes N_{k-1} trials to obtain k-1consecutive successes, then either the next trial is a success and we have our k in a row or it is a failure and we must begin anew. Taking expectations of both sides of the preceding yields
M_k=M_{k-1}+1+(1-p) M_k
or
M_k=\frac{1}{p}+\frac{M_{k-1}}{p}
Since N_1, the time of the first success, is geometric with parameter p, we see that
M_1=\frac{1}{p}
and, recursively
\begin{aligned}& M_2=\frac{1}{p}+\frac{1}{p^2}, \\& M_3=\frac{1}{p}+\frac{1}{p^2}+\frac{1}{p^3}\end{aligned}
and, in general,