# Google Interview Question about a town where if a couple has a girl born, they can't have more children… [duplicate]

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!

• Whatever the rules may be, under the usual assumptions half the children born in the town are girls. – André Nicolas Oct 1 '14 at 19:46
• ^I think that assumes everyone has kids until they have a girl? – Nishant Oct 1 '14 at 19:48
• @Nishant Half of the first children born to each couple are boys. Half of the second children born to those couples who have at least two children are boys. Half of the third children born to those who have at least three children are boys. Whether you go on for ever or terminate after $n$ children, the answer is half. – Mark Bennet Oct 1 '14 at 19:50
• @AndréNicolas I don't understand. You can have 2 boys and 1 girl... or 1000000000 boys and 1 girl.. It's not 1:1... – bodacydo Oct 1 '14 at 20:07
• Suppose you have a jar full of pennies (families). Take one out and flip it. If you get heads (a boy), you flip it again, but if you get tails (a girl), you throw it away (call the results it yielded a "family") and start flipping another penny from the jar. Repeat for a very long time. What fraction of your coin flips will be heads? – Steve Kass Oct 1 '14 at 20:30

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.

• I'm sure it can be shown that in "real life" sequential births from the same parents are not "independent". There are subtle effects that will tend to cause parents of girls to produce more girls and parents of boys to produce more boys. Also, the ratio is not exactly 1:1. So one must ask: Are we talking "real life" or an idealized/theoretical scenario? – Daniel R Hicks Oct 1 '14 at 21:16
• @DanielRHicks I am definitely assuming an idealized situation. The question about sequential births from the same couples is really Biology, but nevertheless interesting, were you speculating or it this a known fact ? – anon Oct 1 '14 at 21:19
• @ReneSchipperus - I've never read anything "hard" on the topic, but I've seen several discussions of the genetic and environmental factors that influence the sex of the infant. – Daniel R Hicks Oct 1 '14 at 21:25
• @DanielRHicks It would be rather harsh if a Google interviewer expected candidates to know conditional probabilities of each sex based on past family history! – chiastic-security Oct 1 '14 at 21:25

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$.

• What if only girls get born though...? Then we'll have 8 boys and 8 girls, then again 8 girls, then again 8 girls.... The ratio gets 8 boys:infinite girls...... – bodacydo Sep 2 '15 at 1:52

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.

• This makes far more sense to me than the coin flipping – Mooing Duck Oct 1 '14 at 22:19
• I would replace those musts with shoulds – ajax333221 Oct 4 '14 at 3:20
• I'm still having hard time understanding this argument one year later... Wouldn't there be more couples who bring girls to registrar...? Isn't is possible that for every boy there would be a couple who brings two girls... and a boy... Sorry I can't understand....... – bodacydo Sep 2 '15 at 1:49

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.

• But what if after having first boy only girls start appearing and never boys...? Then it would be 1 round of boys and infinite round of girls... in the end result ratio of infinite girls:boys in first round..... – bodacydo Sep 2 '15 at 1:50
• @bodacydo That's a different scenario than the one posed. In your scenario, magically, after a boy, only girls follow. Whereas statistically it should be half and half. – paw88789 Sep 2 '15 at 14:32
• Oh boy. Looks like there are math topics I will just never understand... Thanks for your answer, I wish I knew how to understand why statistically it should be half and half. Sometimes women give birth to like 7 baby girls at one time and it's not half and half... This is just beyond me. – bodacydo Sep 2 '15 at 17:50

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?

• Thanks for your interesting question... I've no idea.... – bodacydo Sep 2 '15 at 1:51

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.

• that's not how you calculate a geometric series, or an expected value. If you know y = the probability of x, then E[x] = y, not 1/y. – Red Alert Oct 1 '14 at 22:14

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.

*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.