Solution3
First, we define a Bernoulli random variable
$ X = \left\{ \begin{array}{ll} 0, & the change over does not occur\\ 1, & the change over occurs \end{array} \right. $
Then we can compute
$P(X = 1) = P(1-P)+(1-P)P = P-{P}^{2}+P-{P}^2=2P-2{P}^{2} $
$P(X = 0) = P•P+(1-P)(1-P) = {P}^{2}+1-2P+{P}^2 $
Define Y as the number of changes occurred in n flips, there exists at most n-1 changes
$E(Y)=E(\sum_{i=1}^{n-1}X_i)=\sum_{i=1}^{n-1}E(X_i) $
$E(X_i)=p(X_i=1)=p(1-p)+(1-p)p=2p(1-p) $
$ E(Y)=2(n-1)p(1-p) $.