Thereâ€™s a country where everybody wants to have a son. Therefore each couple keeps having children until they have a boy; then they stop. What fraction of the population is female? (You may assume the question is asked as an expectation of course, since any particular country can be anything in principle â€” 100% girls is possible, just not likely)

Itâ€™s (reportedly) asked as one of the Google interview questions.

The non-mathematician canâ€™t tell you the answer, but believes that the above policy results in more boys. Theyâ€™re wrong (well, ish, for practical purposes itâ€™s good enough). This answer is exactly what (reportedly) Google expect:

Assuming a random arrival pattern of boys and girls: – half of all couples will have a boy as their first child and that is the end of that. – if the other half, whoâ€™ve had a girl, try again, half of them will go on to have a boy and half will go on to have another girl.

So out of 100 couples, we end up with: – 50 having one boy = 50 boys – 25 having one girl and one boy = 25 girls and 25 boys – 25 having two girls = 50 girls

â€¦ and so on.

The logic is good (and it is the logic I had remembered for a long time). It basically says: â€œany given birth has a 50% chance of being a girlâ€, therefore the number of girls in the country will be `number of births * 0.5`

; hence the fraction of the population that is female is 50%. Regardless of stopping criteria.

It took repeated reads of Steve Landsburgâ€™s blog to convince me that even this, cleverer, answer is not correct either.

The faulty assumption in the above analysis is shown by this fact:

$\frac{E[G]}{E[G+B]}\ne E[\frac{G}{G+B}]$

(

$E[\cdot ]$ being the *expectation operator*.) That is to say that the expectation of a ratio is not necessarily equal to the ratio of the expectations.

The error is made by calculating the expectation over all arrangements of individuals instead of over all arrangements of countries.

Weâ€™ll first answer a simpler question by considering a country with only one family. We calculate expectation over all possible one family countries. The possible arrangements of children in that one family country are:

```
N children % girls likelihood
-----------------------------------------------------------
0 B 0% 0.5
1 GB 50% 0.5 * 0.5
2 GGB 66% 0.5 * 0.5 * 0.5
3 GGGB 75% 0.5 * 0.5 * 0.5 * 0.5
4 GGGGB 80% 0.5 * 0.5 * 0.5 * 0.5 * 0.5
5 GGGGGB 83% 0.5 * 0.5 * 0.5 * 0.5 * 0.5 * 0.5
... etc ...
n nG+B n/(n+1) 0.5^(n+1)
```

Remember that expected value is the sum of values multiplied by the probability of that value. So for the specific case of the one family country, we are simply summing up the product of columns three and four in the above table:

${E}_{1}[\frac{G}{G+B}]=\sum _{n=0}^{\infty}\frac{1}{{2}^{n+1}}\frac{n}{n+1}$

Fortunately this is a convergent series, so has a real answer (which the mathoverflow link tells me is):

$1\u2013\mathrm{ln}(2)=30.69$

This should already be sufficient to convince you of the difference between the expectation of a ratio, and the ratio of expectations.

We can do the same for countries with two families; although it gets horrible looking pretty quickly:

```
children % girls likelihood
------------------------------------------------------------
B / B 0% (0.5) * (0.5)
B / GB 33% (0.5) * (0.5 * 0.5)
B / GGB 50% (0.5) * (0.5 * 0.5 * 0.5)
B / GGGB 60% (0.5) * (0.5 * 0.5 * 0.5 * 0.5)
B / GGGGB 66% (0.5) * (0.5 * 0.5 * 0.5 * 0.5 * 0.5)
B / GGGGGB 71% (0.5) * (0.5 * 0.5 * 0.5 * 0.5 * 0.5 * 0.5)
... etc ...
GB / B 33% (0.5 * 0.5) * (0.5)
GB / GB 50% (0.5 * 0.5) * (0.5 * 0.5)
GB / GGB 60% (0.5 * 0.5) * (0.5 * 0.5 * 0.5)
GB / GGGB 66% (0.5 * 0.5) * (0.5 * 0.5 * 0.5 * 0.5)
GB / GGGGB 71% (0.5 * 0.5) * (0.5 * 0.5 * 0.5 * 0.5 * 0.5)
GB / GGGGGB 75% (0.5 * 0.5) * (0.5 * 0.5 * 0.5 * 0.5 * 0.5 * 0.5)
... etc ...
```

Yuck. Regardless of how nasty this is getting, the expectation for two families is:

${E}_{2}[\frac{G}{G+B}]=\sum _{n=0}^{\infty}\frac{n+1}{{2}^{n+2}}\frac{n}{n+2}$

Iâ€™m afraid, that the mathoverflow article loses me then; as I have never heard of the â€œdigamma functionâ€ it talks about. I can see what itâ€™s doing though â€” itâ€™s simply a way of converting the infinite sum expression into a direct equation.

Leaving that nightmare to the real mathematicians, for our purposes all we care about is that

${E}_{k}[\frac{G}{G+B}]\to \frac{1}{2}\u2013\frac{1}{4k}\to 50\%$as

$k\to \infty $. Importantly though: it never quite reaches it.

Executive summary: **The expected percentage of girls in a country of **

**$k$**

** families, operating the â€œstop on boyâ€ policy, is less than 50%**.

There is actually an awful lot more to this problem. A fascinating follow up guest post at Steve Landsburgâ€™s is worth reading.