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?