Expected Adjacent Boy-Girl Pairs in a Random Line
$b$ boys and $g$ girls stand in a line of length $b + g$, arranged uniformly at random. A "boy-girl position" is any pair of consecutive spots in the line where one person is a boy and the other is a girl.
Find the expected number of boy-girl positions.
As a concrete example, the arrangement $BGGBBGB$ (with $b = 4$, $g = 3$) has 4 boy-girl positions: $(B,G)$ at spots 1-2, $(G,B)$ at spots 3-4, $(B,G)$ at spots 5-6, and $(G,B)$ at spots 6-7.
Evaluate your answer for $b = 10$ and $g = 15$.
Hints
- When you need the expected count of overlapping or dependent events, think about indicator random variables and linearity of expectation -- you never need to handle the dependence directly.
- Define an indicator $I_i$ for each consecutive pair $(i, i+1)$. By symmetry of a uniform random permutation, $E[I_i]$ is the same for every $i$.
- Compute $P(I_1 = 1)$ by counting: out of $(b+g)(b+g-1)$ ordered ways to fill two spots, exactly $2bg$ place one boy and one girl.
Worked Solution
How to Think About It: Whenever you need the expected count of events that are not independent, reach for indicator random variables and linearity of expectation. Here, define an indicator for each consecutive pair of positions and ask: does that pair contain one boy and one girl? The beauty of linearity of expectation is that you never need to worry about dependence between different pairs -- you just compute the probability for a single pair and multiply by the number of pairs.
Quick Estimate: There are $b + g - 1 = 24$ consecutive pairs. For any single pair, the chance of getting one boy and one girl is roughly $2 \times \frac{b}{b+g} \times \frac{g}{b+g} = 2 \times \frac{10}{25} \times \frac{15}{25} = 0.48$. Multiply: $24 \times 0.48 = 11.52$. So the answer should be around 12. (This slightly underestimates because the exact calculation uses sampling without replacement, but for $n = 25$ the correction is small.)
Approach: Define indicator variables $I_i$ for each consecutive pair $(i, i+1)$, compute $P(I_i = 1)$ exactly using combinatorics, and apply linearity of expectation.
Formal Solution:
Let $I_i$ be the indicator that positions $i$ and $i+1$ contain one boy and one girl, for $i = 1, 2, \ldots, b+g-1$. The total count of boy-girl positions is:
$$T = \sum_{i=1}^{b+g-1} I_i$$
Since the line is a uniformly random permutation, every pair of positions is exchangeable. So $E[I_i] = E[I_1]$ for all $i$, and by linearity of expectation:
$$E[T] = (b+g-1) \cdot E[I_1]$$
Now compute $E[I_1] = P(\text{positions 1 and 2 have different genders})$. The total number of ordered ways to fill two spots from $b+g$ people is $(b+g)(b+g-1)$. The number of ways to place one boy and one girl in those two spots is $2bg$ (choose which spot the boy occupies, then pick a boy and a girl). So:
$$E[I_1] = \frac{2bg}{(b+g)(b+g-1)}$$
Plugging in:
$$E[T] = (b+g-1) \cdot \frac{2bg}{(b+g)(b+g-1)} = \frac{2bg}{b+g}$$
The $(b+g-1)$ terms cancel cleanly, giving a remarkably simple formula.
Answer: The expected number of adjacent boy-girl positions is $\frac{2bg}{b+g}$. For $b = 10$, $g = 15$: $\frac{2 \cdot 10 \cdot 15}{25} = \frac{300}{25} = 12$.
Intuition
This problem is a textbook illustration of why linearity of expectation is so powerful: it lets you compute the expected value of a sum without knowing anything about the joint distribution of the summands. The indicators $I_1, \ldots, I_{b+g-1}$ are not independent (knowing that positions 1-2 are both boys makes it more likely that positions 2-3 form a boy-girl pair), but linearity of expectation does not care. You just need the marginal probability for each indicator, and symmetry hands that to you on a plate.
The clean formula $2bg/(b+g)$ has a nice interpretation: it equals $2 \times$ the harmonic-mean-style combination of $b$ and $g$, divided across the line. When $b = g = n$, the answer is simply $n$ -- exactly half the $2n - 1$ pairs are boy-girl transitions on average. In trading interviews, this type of indicator-variable counting shows up whenever you need to price a payoff that depends on the number of times a sequence changes state (e.g., sign changes in returns, regime switches). The technique is always the same: decompose, compute one indicator, multiply.