The problem
A couple decides to have a male child no matter what. If their first child is a son, they stop; if it is a daughter, they continue having more children. There is no upper limit on how many daughters they can have before having a son. What is the average number of sons and daughters they will have?
I was once asked this question during a job interview. My solution at the time was intuitive, but it lacked mathematical rigor. In this post, I present you with three solutions, to various degrees of mathematical refinement.
To fix notation: let be the probability of having a daughter, and that of having a son. In the original interview , but keeping things general allows for (1) more concise equations (2) less likelihood of two answers agreeing by coincidence.
1. The brute force approach
One part of the question is actually easy to answer: how many boys will the family have in the end. The answer is 1, with probability 100% - since the couple will not stop until having a boy, and won’t have another son once they have the first, they are guaranteed to have one and only one boy. The expected number of sons is then 1, and we can focus on finding the number of daughters next.
A logical way to get started is to write down the probabilities of the couple having children, as follows:
- 1 child (0 daughters): probability (just have a son and stop)
- 2 children (1 daughter): probability (have a daughter and then have a son)
- 3 children (2 daughters): probability (have two daughters and then have a son)
- …
One sees that
or, in terms of the number of daughters,
Therefore, the expected number of daughters will be
The sum without the factor is found to be
which can be derived by:
- Using basic calculus and the expression for the sum of a geometric series
- Massaging the expression until you find yourself a geometric series
Approach (2) is actually equivalent to the second approach we discuss in the next chapter, so we omit it for now. We will then write approach (1) here for completeness; it is a very common technique for summing a series.
Rewrite the sum (which, by the way, can start from with no loss of generality) as
where we used the common formula from ordinary calculus. Taking the derivative out (hoping that the series converges), we have
where we used the formula for the sum of a geometric series with starting term and ratio . Taking the derivative gives
as claimed. Therefore,
or
For the total number of children,
With , we get the result
and the total number of children is 2: one son, one daughter.
2. The intuitive (recursive) approach
As correct as the result above is, I always found it lacking; it is purely computational and doesn’t provide a lot of intuition for what is going on. The approach I used during the actual interview was different:
Let be the expected total number of children. I first wrote:
- With probability , the couple has a son (and stops);
- With probability , the couple has a daughter and then needs to start having children again.
Now, “start having children again” felt like somewhat going back to the beginning: aside from the fact the couple now had one child, they had “reset” and would be starting again. We could illustrate the process as something like this (with blue denoting a son, and pink denoting a daughter):

This self-repeating, potentially infinite structure reminded of a class of problems that sometimes appears in university entry exames for engineering schools, namely that of a circuit consisting of an infinite number resistors: one is given a network of resistors, each with resistance , and is required to find the equivalent resistance:

(image from this page)
We learn how to calculate equivalent resistances for circuits in parallel or in series, but since this is infinite, at first it seems impossible to compute.
The trick for solving this type of problem is to realize that we can find a portion of the system that is self-similar, namely the region circled in red is exactly equivalent to the whole system of resistors:

This is only possible since the number of resistors is infinite - were it finite, there would not be an exact match between the part circled in red and the total circuit.
This realization allows us to write a consistency condition for the equivalent resistance by using standard rules for serial / parallel resistors:
with solution .
My idea was to do something similar for our babies problem: using the notion that the system “resets” after the first daughter, I could write the recursive relation
That is: with probability we have a son and stop; with probability , we have a daughter and start again the process of having children. , our unknown, appears in both sides.
We can then write
or
Notice that this is just a rewriting of
i.e. the fact that we get 1 son and daughters, as we proved before. It works!
We now tackle the reason why I mentioned that this self-repeating business is actually a means to calculate the infinite sum we saw before, namely
Let us show this now. We will start from this sum, break it down, and identify a copy of itself inside of it.
First, rewrite the identity as
We will prove that, by using that is the number of boys (1) + the number of daughters derived from the previous section,
then this identity, , is satisfied; we won’t need any calculus for this, and just the geometric series alone will be sufficient.
Multiplying the expression above by we get
and we have our proof. Essentially, we were able to compute indirectly by finding it inside its own expression, multiplied by .
3. The Markov chain approach
The third (and, in my opinion, most elegant) approach uses Markov chains.
It considers that there are two states in the world: one where we had a son, and one where we still haven’t:

The “had a son” state is, in Markov chain lingo, an absorbing state: once we get there, we never leave (the probability of staying in it is 1). On the other hand, the “still no sons” state is transient: with probability we stay in it, but with probability we migrate to the absorbing state.
This is the classic example of an absorbing Markov chain: there is one absorbing state and one transient state. Let’s dive a bit into the theory.
Recall that in (finite) Markov state theory we denote the probability of transitioning between an initial state and a final state as , the collection of which can be represented as a transition matrix . represents the probabilities of going from one state to another in a single step. Analogously, for any power , the matrix element can be interpreted as the probability of going from to in exactly steps.
In our case, the transition matrix is very simple and given by
In general, for a more complex system with transient states and absorbing states, takes a block-wise form
where is matrix of transition probabilities among transient states and is a matrix of transition probabilities from transient to absorbing states.
As we mentioned above, taking powers of measures how likely it is to go from a state to a state in steps. We may consider, then, how likely it is to go from a state to another at any number of steps - this gives rise to the Markov chain’s fundamental matrix:
where the second equality is equivalent to the geometric series for scalars. Notice that only the submatrix appears here! The fundamental matrix is key to measuring how many times we will visit transient states before eventually being absorbed.
For our problem, is just the 1x1 submatrix , hence is just a number given by
There is only one transient state, that of still not having a son; this means that we will visit this state times. We are done: this is the number of children we have before we stop.
Takeaways
Even though you can have, in principle, an infinite number of children, do not worry - you’re most likely to only have a boy and a girl :)
Happy holidays and a happy 2025!