Confusion with Expected Value I'm having some trouble with this question:
If I line up n boys and m girls, what is the expected number of times that a girl comes directly after a boy in the line?
I'm not really sure how to approach it- how can I model this situation?
 A: Let me introduce you to indicator variables, these are a fantastic tool used in calculating expectations.
If I toss $10$ coins what is the expected number of heads? You should know this as $5$ but let me show you another method. Let $S$ be the random variable, number of heads. Let each $X_i$ be $1$ if the $i^{th}$ coin is heads and $0$ otherwise. It should then be clear that
$S = \sum\limits_{i=1}^{10 } X_i$
Then taking expectation, and using its linearirty, we have that $\mathbb{E}[S] =  \mathbb{E}[\sum\limits_{i=1}^{10}X_i] = \sum\limits_{i=1}^{10}\mathbb{E}[X_i] = \sum\limits_{i=1}^{10}\mathbb{P}[X_i=1] \cdot 1 + \mathbb{P}[X_i=0] \cdot 0 = \sum\limits_{i=1}^{10}\mathbb{P}[X_i=1] =  \sum\limits_{i=1}^{10}\frac{1}{2} =5 $
Naturally, you are thinking " Okay funny man well done, I already knew how to do that! I want my problem solved. " Here is how we can use indicator variables in your case:
We have a total of $n+m$ spots in our line, of which all but the first could result in a girl in front of a boy.
Hence $n+m-1 $ potential chances for our desired event.
Let $X_i$ for $i =
2 , 3,\dots,n+m$ be the indicator of the $(i-1)^{th}$ person is a boy and the $i^{th}$ a girl. That is $1$ if we have $BG$ in spot $i-1, i$ and $0$ otherwise.  Let $S$ denote the total number of times we have a boy followed by a girl.
Hence the total number of times we have a boy followed by a girl is: 
$S = \sum\limits_{i=2}^{n+m}X_i$
We are nearly done now, we just need to take advantage of the linearity of expectation. We see that as before $\mathbb{E}[S] = \sum\limits_{i=2}^{n+m}\mathbb{E}[X_i]$
And so to finish this problem we simply need to find $\mathbb{E}[X_i]$
The $X_i$ are most definitely not independent, however we do not care as expectation is linear. However they are identically distributed! And so we only need to for example find $\mathbb{E}[X_2]$.
$\mathbb{E}[X_2] = \mathbb{P}[X_2 =1]\cdot 1 + \mathbb{P}[X_2 = 0]\cdot 0 = \mathbb{P}[X_2 =1]$
(this is true for all indicator variables, that is their expectation is simply the probability they are $1$)
$\mathbb{P}[X_2 = 1] = \frac{n}{n+m} \cdot \frac{m}{n+m-1}$ as we need a boy to be the first person in the line and then a girl to be second.
Hence $\mathbb{E}[S] = \sum\limits_{i=2}^{n+m}\mathbb{E}[X_i] =\sum\limits_{i=2}^{n+m} \frac{n}{n+m} \cdot \frac{m}{n+m-1} = (n+m-1) \cdot \frac{n}{n+m} \cdot \frac{m}{n+m-1} = \frac{nm}{n+m} $
And we are done!
You could check this for the simple case $n=m=1$ and note that we either have $BG$ or $GB$ both we equally probability and so $\mathbb{E} = \frac{1}{2} $ in this case, which agrees with our formula $\frac{1\cdot 1}{1 +1 }$
