# What is the expected number of coin flips, if you stop when the first coin flip is the same as the last?

In order to calculate the $\text{E}[X]$ where $X$ is the number of total coin flips, this is the approach I took:

The probabilities are:

$Pr(H) = p$

$Pr(T) = (1-p)$

Define indicator random variables:
$H_i$ = 1 if $i$'th flip is heads = 0 if $i$'th flip is tails

$T_i$ = 1 if $i$'th flip is tails = 0 if $i$'th flip is heads

Now, there are two possible events that could occur:

$A =\{\ H ...TTT...H \}\ ~~~~or~~~~~B=\{\ H ...TTT...H \}$

so $\text{E}[X] = Pr(A)\cdot \text{E}[A] + Pr(B)\cdot \text{E}[B]$.;

$\text{E}[A]=\sum_{k=1}^\infty Pr(H_i)\cdot \text{E}[H_{i}]=\sum_{k=1}^\infty pkp^k = p\sum_{k=1}^\infty kp^k$ $\text{E}[B]=\sum_{k=1}^\infty Pr(T_i)\cdot \text{E}[H_{i}]=\sum_{k=1}^\infty (1-p)k(1-p)^k =(1-p) \sum_{k=1}^\infty kp^k$

Is this right so far? Because I'm hinted that I should get and use the formula for $\sum_{k=1}^\infty kx^{k-1}$, but I don't understand why there should is a $k-1$ as an exponent. Where did the $-1$ come from?

• Do you mean, "What is the expected number of coin flips, if you stop when a coin flip is the same as the last?"? Also, please add the [self-study] tag & read its wiki. – gung - Reinstate Monica Dec 15 '14 at 0:30
• @Timmy A similar question has been asked on math, you mind find it helpful: math.stackexchange.com/questions/364038/… – mugen Dec 15 '14 at 0:40
• Your A and B events are identical. I presume you want to interchange H and T on one of them – Glen_b Dec 15 '14 at 0:56