Google Interview Question about a town where if a couple has a girl born, they can't have more children...

5k Views Asked by At

Today I was reading about Google Interview math puzzles and I couldn't solve the following puzzle.

Imagine a town where there is a law:

If a couple have a girl born, then they can't have more children. If they have a boy born, then they can have more children. They keep having children until a girl is born.

Question is: What is the portion of girls to boys in town.

I'm trying to solve it using mathematics. Here is my approach but I'm not getting anywhere. I'm using probabilities to model this world.


Probability that a new couple has 1 boy is 1/2.

Probability that a new couple has 1 girl is 1/2.


Probability that a couple with 1 boy has 2 boys is 1/4.

Probability that a couple with 1 boy has 2 girls is 0. (You can only have 1 girl by law.)

Probability that a couple with 1 boy has 1 boy and 1 girl is 1/4.


Probability that a couple with 2 boys has 3 boys is 1/8.

Probability that a couple with 2 boys has 3 girls is 0. (You can only have 1 girl by law.)

Probability that a couple with 2 boys has 2 girls is 0. (You can only have 1 girl by law.)

Probability that a couple with 2 boys has 2 boys and 1 girl is 1/8.


Probability that a couple with 3 boys has 4 boys is 1/16.

Probability that a couple with 3 boys has 4 girls is 0. (You can only have 1 girl by law.)

Probability that a couple with 3 boys has 3 girls is 0. (You can only have 1 girl by law.)

Probability that a couple with 3 boys has 2 girls is 0. (You can only have 1 girl by law.)

Probability that a couple with 3 boys has 3 boys and 1 girl is 1/16.


At this moment I'm starting to see a pattern. If couple has a boy, then with equal probability they can have a girl as well.

So I sum all the probabilities of all couples in town (infinite number of couples), and I multiply probability by number of boys:

$Boys in Town = 1*1/2 + 2*1/4 + 3*1/8 + 4*1/16 + ...$

I get infinite series:

$ 1/2 + 1/2 + 3/8 + 4/16 + 5/32 + ...$

I sum it up and I get:

$ 1 + 3/8 + 4/16 + 5/32 + ...$

(I don't know how to sum this)

So there will be more than 1 boy for sure!

So I think in this town the ratio will be that there are more boys than girls.

In particula there wil be $ 3/8 + 4/16 + 5/32 + ...$ boys more than girls in town.

There will be 1 girl and 1 + $ 3/8 + 4/16 + 5/32 + ...$ boys.


Please let me know what you think of my analysis. Thanks!

8

There are 8 best solutions below

1
On

Say there are $16$ couples. That is $8$ girls and $8$ boys. The latter $8$ couples have a second round of children. That is $4$ more girls and $4$ boys. The latter $4$ couples have more children $2$ girls and $2$ more boys. The last $2$ couples have another girl, and one boy. This final couple can have some boys until they get a girl, but again the ratio to a close approximation will be $1:1$.

1
On

I am assuming that the problems implies that families continue to have kids until they have a girl.

Let $B$ be the number of boys a family has. $B$ is therefore a geometric random variable with probability $p = \frac{1}{2}$. Let $S$ be the total number of boys. That is $$ S_n = B_1 + B_2 + ... + B_n$$ where $n$ is the number of families, and also the number of girls, since every family will have at least and at most one girl.

The ratio of boys to girls is then $\frac{S}{n}$ and the expected value of the ratio is $E[\frac{S}{n}] = \frac{nE[B]}{n} = E[B] = \frac{1-p}{\text{p}}= \frac{\frac{1}{2}}{\frac{1}{2}}=1$.

That is, there is 1 boy for every 1 girl.

4
On

Every birth is an independent event.

Thus regardless of who is allowed to procreate the ratio will be $1:1$.

In order to change that ratio you will have to start killing babies.

1
On

Think about it as coin flips. You flip a coin and keep flipping to you get heads. Then pass coin to another person who also flips to they get heads. Do this again and again. what will ratio of heads to tails be?

0
On

While you can model this by recognizing that this is a geometric random variable and using the properties thereof, you can also identify the expectation using the total expectation formula and the Markov property. Specifically, let $N_b$ be the number of boys in a family. Then

$$E(N_b) = E(N_b | \text{ first child is male }) P( \text{ first child is male }) + E(N_b | \text{ first child is female }) P(\text{ first child is female }) \\ = (1+E(N_b))/2 + 0.$$

From this we conclude $E(N_b) = 1$. For girls, let $N_g$ be the number of girls in a family. Then by an analogous argument

$$E(N_g) = E(N_g)/2 + 1/2$$

from which we conclude that $E(N_g)=1$. So your ratio is 1.

3
On

Of all firstborns, half will be boys and half will be girls (expected). Some couples, those with boys in round one, will be eligible to have another child. Some of these eligible couples may elect to have another child, some may not. But of the children born in the second round, half will be boys and half will be girls (expected). And so on. The ratio remains 1:1 at all times.

3
On

Here's an easy way to see that it's 1:1.

Suppose you're a registrar. Your job is to record births, and write down for each one whether it's a boy or a girl. Every time someone has a baby, they bring the baby to you, and you write down "boy" or "girl".

The rules of when you're allowed to have another child are completely irrelevant, and just there to throw you off track. It should now be pretty clear that as the babies are brought through your office, one at a time, and you make your notes, half of them must be boys and half of them must be girls. Who the parents are, and whether they have other children, has nothing to do with it.

0
On

*I can't comment, and am not a maths expert, but I am going to risk the down vote.

"Question is: What is the portion of girls to boys in town."

"If a couple have a girl born, then they can't have more children. If they have a boy born, then they can have more children. They keep having children until a girl is born."

*I am assuming the above "portion" means proportion.

The answers here are stating that it is an independent event and so is 1:1, but this would be an answer to the question "what is the probability of having a girl in this town?".

Firstly, if my understanding of the question is correct, then the answer could be anything from 0:1 to 1:0 because the proportion is not known from a probability.

I will change my interpretation of the question to: What is the probability of girls and boys in the town."

The chance of having a girl is 1/2 and the same for a boy. The last child will be a girl.

The chance of a boy will be 1/2 + 1/4 + 1/8 + 1/16... -> 1/((n+1)squared). The last child will be a girl and everything before which is higher in probability will be a boy so appears it will not be 1:1. However, because no boys will be born after a girl these probabilities should be subtracted.

*Please improve this answer.