Boys and Girls

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.

Get a free subscription to Oracle magazine published by Oracle Corp.
 Powered by Max Banner Ads 

Related posts:

  1. 10 Google Interview Puzzles
  2. Probability of a Car Passing By
  3. Pick a Random Byte

8 Responses

  1. kevin says:

    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?

  2. Ernelli says:

    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.

  3. rich says:

    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

  4. Frank says:

    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.

  5. jeo says:

    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?

  6. Silas says:

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

  7. Silas says:

    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.

  8. Cikicikibaba says:

    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!

Leave a Reply

Using Gravatars in the comments - get your own and be recognized!

XHTML: These are some of the tags you can use: <a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>