expected value of getting a head or a tail right after each other when flipping a fair coin we flip a fair coin N times. the probability getting a head or a tail is of course 0.5. after N tossings, we record a sequence of heads and tails. let A be the total number of times that we get a head right after we get a tail. let B be the total number of times that we get a tail right after we get a head. for example, if we flip the coin 7 times and record a result as HHTTHTH, then A=2 and B=2.
find E(A) and E(B).
i relate this problem to the famous coin changeover problem. i got stuck right from the beginning. thanks for any help.
 A: A start: Define random variables $X_1,X_2,\dots, X_{N-1}$ by $X_i=1$ if at $i$ we get a tail and at $i+1$ we get a head. So $X_1+X_2+\cdots+X_{N-1}$ is the number of tail to head transitions. By the linearity of expectation, $E(X_1+\cdots+X_{N-1})=E(X_1)+\cdots+E(X_{N-1})$.
But $\Pr(X_i=1)=\frac{1}{4}$, so the expected number of tail to head transitions is $\frac{N-1}{4}$. 
For the variance, we would like to find first $E((X_1+\cdots+X_{N-1})^2$, and subtract the square of the expectation of $X_1+\cdots+X_{N-1}$. The calculation is similar to the previous one, but quite a bit more complicated. Expand $(X_1+\cdots+X_{N-1})^2$. Again, use the linearity of expectation. 
Added: When we expand $(X_1+\cdots+X_{N-1})^2$, we get $\sum X_i^2$ plus "mixed" terms. The expectation of $\sum X_i^2$ has already been calculated, sine $X_i^2=X_i$. The mixed terms $X_iX_j$ can be divided into two types. The numbers $i$ and $j$ could be consecutive. For such $i,j$ we have $X_iX_j=0$. Or they could be non-consecutive. There are $\binom{N-1}{2}$ unordered pairs, of which $N-2$ are consecutive, leaving $\frac{(N-2)(N-3)}{2}$ non-consecutive pairs. For such a pair $\{i,j\}$, we have $\Pr(X_iX_j=1)=\frac{1}{2^4}$. But for each pair $\{i,j\}$ we have the term $2X_iX_j$. So the expectation of the mixed terms is $\frac{N-2)(N-3)}{2^4}$.  
