Independent trials, each of which is a success with probability p, are performed until there are k consecutive successes. What is the mean 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[N_{k}]=E[E[N_{k}|N_{k-1}]]Now,
E[N_{k}|N_{k-1}]=N_{k-1}+1+(1-p)E[N_{k}]where the preceding follows since if it takes N_{k-1} trials to obtain k − 1 consecutive 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
M_{2}=\frac{1}{p}+\frac{1}{p^{2}},M_{3}=\frac{1}{p}+\frac{1}{p^{2}}+\frac{1}{p^{3}}
and, in general,
M_{k}=\frac{1}{p}+\frac{1}{p^{2}}+\cdot\cdot\cdot+\frac{1}{p^{k}}