Hi all!


Google published recently questions that are asked to candidates on interviews. One of them caused very very hot debates in our company and we're unsure where the truth is. The question is:



> 
> In a country in which people only want
>  boys every family continues to have
>  children until they have a boy. If
>  they have a girl, they have another
>  child. If they have a boy, they stop.
>  What is the proportion of boys to
>  girls in the country?
> 
> 
> 


Despite that the official answer is 50/50 I feel that something wrong with it. Starting to solve the problem for myself I got that part of girls can be calculated with following series:


$$\sum\_{n=1}^{\infty}\frac{1}{2^n}\left (1-\frac{1}{n+1}\right )$$


This leads to an answer: there will be ~61% of girls.


The official solution is:



> 
> This one caused quite the debate, but
>  we figured it out following these
>  steps:
> 
> 
> * Imagine you have 10 couples who have 10 babies. 5 will be girls. 5
>  will be boys. (Total babies made: 10,
>  with 5 boys and 5 girls)
> * The 5 couples who had girls will have 5 babies. Half (2.5) will be
>  girls. Half (2.5) will be boys. Add
>  2.5 boys to the 5 already born and 2.5 girls to the 5 already born. (Total
>  babies made: 15, with 7.5 boys and 7.5
>  girls.)
> * The 2.5 couples that had girls will have 2.5 babies. Half (1.25) will
>  be boys and half (1.25) will be girls.
>  Add 1.25 boys to the 7.5 boys already
>  born and 1.25 girls to the 7.5 already
>  born. (Total babies: 17.5 with 8.75
>  boys and 8.75 girls).
> * And so on, maintianing a 50/50 population.
> 
> 
> 


Where the truth is?



Google question: In a country in which people only want boys
The proportion of girls in one family is a [biased estimator](http://en.wikipedia.org/wiki/Bias_of_an_estimator) of the proportion of girls in a population consisting of many families because you are underweighting the families with a large number of children.


If there were just 1 family, then your formula would be wrong, but the average of the percentage of girls you would observe would be


$$\sum\_{n=0}^\infty \frac{1}{2^{n+1}} \bigg(\frac{n}{n+1}\bigg) = 1-\log2 = 30.69\%.$$


Half of the time, you would observe $0\%$ girls.


If you have multiple families, the average of the observed percentage of girls in the population will increase.


For 2 families, the average percentage of girls would be


$$\sum\_{n=0}^\infty \frac{n+1}{2^{n+2}} \bigg(\frac{n}{n+2}\bigg) = \log 4 - 1 = 38.63\%.$$


More generally, the average percentage for $k$ families is


$$\sum\_{n=0}^\infty \frac{n+k-1 \choose k-1}{2^{n+k}} \bigg(\frac{n}{n+k}\bigg) = \frac{k}{2}\bigg(\psi\left(\frac{k+2}2\right)-\psi\left(\frac{k+1}2\right)\bigg)$$


where $\psi$ is the [digamma function](http://en.wikipedia.org/wiki/Digamma_function) which satisfies


$$ \psi(m) = -\gamma + \sum\_{i=1}^{m-1} \frac1i = -\gamma + H\_{m-1}$$
$$ \psi\left(m+\frac12\right) = -\gamma -2\log 2 + \sum\_{i=1}^m \frac{2}{2i-1}.$$


With a little work, one can verify that this goes to $1/2$ as $k\to \infty$. So, for a large population such as a country, the official answer of $1/2$ is approximately correct, although the explanation is misleading. In particular, for $10$ couples, the expected percentage of girls is $10 \log 2 - 1627/252 = 47.51\%$ contrary to what the official answer suggests. With $k$ families, the expected proportion is about $1/2 - 1/(4k)$.


It is not enough to argue that the expected number of boys equals the expected number of girls, since we want $E[G/(G+B)] \ne E[G]/E[G+B].$ Expectation is linear, but not multiplicative for dependent variables, and $G$ and $G+B$ are not independent even though $G$ and $B$ are.


