[Math] Successes or failures in a row

probabilityprobability theory

Let random variable $X$ be defined as the number of independent Bernoulli(p) trials required until we observe either two successes or two failures in a row. Find $P(X=n)$ for $n=2,3,4, \ldots$ Then find the expectation and variance of $X$.

Okay so since there has to be two successes or failures in a row, the trials have to alternate $SFSFSF…$ or $FSFSFS…$ until it comes upon two successes or two failures. I initially tried using the Negative Binomial Distribution here but I remembered that it doesn't take order into account so that wouldn't work. Then I tried breaking it up into if $n$ is odd vs. if $n$ is even but but I didn't really know where to go from there…

Best Answer

You can try a simple bookkeeping here like this. If $p$ is the probability of success, than, obviously, you get $$ P(X=2)=p^2+(1-p)^2=1-2p+2p^2, $$ because either you have two successes or two failures, and these two events are disjoint. Next, $$ P(X=3)=(1-p)p^2+p(1-p)^2=(1-p)p. $$ Two more: $$ P(X=4)=p(1-p)p^2+(1-p)p(1-p)^2=(1-p)p(1-2p+2p^2). $$ $$ P(X=5)=(1-p)p(1-p)p^2+p(1-p)p(1-p)^2=(1-p)^2p^2. $$ Do you see a pattern here? If not, try a couple more values for $n$. Finally, you get $$ P(X=2k)=(p(1-p))^{k-1}(1-2p+2p^2),\quad k=1,2,\ldots $$ $$ P(X=2k+1)=(p(1-p))^{k},\quad k=1,2,\ldots $$ The sanity check shows that $\sum_k [P(X=2k)+P(X=2k+1)]=1$ as it should be.

Using the found distribution it is possible to find $E[X]$ and Var$[X]$ if you know how to find sums of the form $$ \sum_k kp^k,\quad \sum_k k^2p^k. $$