**Question:** In a country where everyone wants a boy, each family continues having babies till they have a boy. After some time, what is the proportion of boys to girls in the country? (Assuming probability of having a boy or a girl is the same)

**Answer:** This is a very simple probability question in a software interview. This question might be a little old to be ever asked again but it is a good warm up.

Assume there are C number of couples so there would be C boys. The number of girls can be calculated by the following method.

Number of girls = 0*(Probability of 0 girls) + 1*(Probability of 1 girl) + 2*(Probability of 2 girls) + …

Number of girls = 0*(C*1/2) + 1*(C*1/2*1/2) + 2*(C*1/2*1/2*1/2) + …

Number of girls = 0 + C/4 + 2*C/8 + 3*C/16 + …

Number of girls = C

(using mathematical formulas; it becomes apparent if you just sum up the first 4-5 terms)

The proportion of boys to girls is **1 : 1**.

Challenge yourself with more probability questions or interview puzzles.

If you have any questions, please feel free to send me an email at support@mytechinterviews.com. If you have any interview questions which you feel would benefit others, I would love to hear about it.

**If you're looking for some serious preparation for your interviews, I'd recommend this book written by a lead Google interviewer. It has 189 programming questions and solutions:**

First Generation:

G1+B2=B10

G3+B4=G11,B12

G5+B6=G13,B14

G7+B8=B15

Second Generation:

B10+G12=B100

B12+G13=G101,B102

Third Generation:

B100+G101=B1000 / G1001,B1002

Something wrong here. Probability for the family to have two girls in a row is 1/2 · 1/2 = 1/4. Probability of having boy after a girl is 3/4. How can you get a ratio of 1:1 like that?

Every time a couple has a child half the time it’s a boy no matter what.

Kevin: Assuming the second family gets a boy the second time breaks the randomness of the scenario. In the second “try”, family 1 has a boy and is done. Family 2 already has a girl, and then gets boy or girl with 50% probably. The ratio is still 1:1 (or 1.5:1.5 in this case)

There are LOTS of other factors with this question as well. For example… what country? And how long is “after some time?” To me, this is similar to asking someone how many lottery tickets they would have to buy to guarantee a win. Help? Context?

The difference in number is just a martingale, so the difference is 0 in expectation. The expected value of the ratio, however, is not 1 (because changes in population affect the ratio in a nonlinear fashion, so our ratio becomes a biased estimator of what happens in the limit).

I thought 1:1 is correct. Let me put it in easy way.

Suppose there are 100 families. Now since there is equal probability of having a boy/girl. So 50 families got a boy and 50 will got a girl. Now the families that are having girl will try again. So 25 of them will get a boy and other 25 will get a girl. and repeat this process………

Now calculate the total number of boys and girls. You will get the answer 100 boys and 100 girls.

Now forget the 100 families. Extending to general case then you will find that the proportion is 1:1

Any objection/suggestion?

I totally agree with JEO!!! Why do you go for mathematical calculations for simple questions?

The probably must be 2(boys) : 1(girls)……..

consider 2 families.. Since probably of getting a boy and a girl is equal, we can say that one family gets a boy and the other gets a girl. But, since the second family has only a girl, it gets another boy.

Now there are TWO BOYS AND ONE GIRL. Hence the probability must be 2:1 and not 1:1.

Any objections to this?

A more direct way of solving the problem is to consider the birth of children as a stream producing boys and girls with a 50% chance.

To get n, boys one picks the first n boys in the stream and the number of girls in between will on average be n as well.

No math req., after all couples have the fist child, 50% have boys & they are done, the other 50% have girls so now 1:1. the girl parents now have a 2nd child & half have boys and they are done, the other half have girls so again ratio is 1:1, those having girls have a 3rd child & again half are boys & half are girls so again the ratio is 1:1, Ad infinitum

A less formal way would be to say, okay, everyone start having babies. First set half are boys and half are girls (1:1). Now all those with girls, start having babies. Half are boys and half are girls (1:1). And so on.

Ok, so I thought of this differently…

Couple #1 try for a baby. They have a 50% chance of having a boy and a 50% chance of having a girl. Lets roll the die and … op its a boy. They stop making babies. Lets say couple #2 try and op its a girl so… they now try again… the odds are that they will have a boy. So they stop. Keep playing the odds and you should have a ratio of 2:1 for boys. I know this is not using crazy math, and it assumes that the if the first child is a girl the second one is a boy but the odds are 50/50.

Any thoughts?

uh, I suppose the last equation should be lim_{n->infty} S/2 = 1

If you would like to be more rigorous in calculated the expected number of girls, it is possible derive an explicit formula for the partial sums.

Let S/2 := sum k/(2^(k+1))

i.e. S = sum k/(k^k)

[Where all my sums are over k running from 1 to n]

We have:

S = 1/2 + 2/4 + 3/8 + 4/16 + 5/32 + …

Rearranging:

S = 1/2 + 1/4 + 1/4 + 2/8 + 1/8 + 3/16 + 1/16 + 4/32 + 1/32 + …

Separating odd and even terms:

S = (1/2 + 1/4 + 1/8 + …) + 1/2 (1/2 + 2/4 + 3/8 + …)

Whence we see our original series S is exactly the second bracket. So:

S = (1/2 + 1/4 +…) + 1/2 S

And,

S/2 = (1/2 + 1/4 + 1/8 +…)

Which is our expected number of girls, but the right hand side is just the geometric series with a ratio of 1/2 between terms. It is easy to show the sum from k = 1 to n of a geometric series with ratio r is r(1-r^n)/(1-r), which for r = 1/2 is just 1-(1/2)^n. So:

S/2 = 1-(1/2)^n

Taking the limit as n tends to infinity gives the expected number of girls per family, S/2 = 1.

This is a very simple example of Negative Binomial Distribution , where the failure is having a boy. So the question is what is the mean value of number of girls born before having one failure(boy)? It is shown that this is p/(1-p), where in our case p = 0.5. So the mean value is 1. We also know that there is always 1 boy in the family. So the ratio is 1:1.

Hope it helps for someone!