Expected number of children question from "Introduction to Probability" This question appeared on Introduction to Probability (by Joe Blitzstein and Jessica Hwang)

A couple decides to keep having children until they have at least one
boy and at least one girl, and then stop. Assume they never have
twins, that the “trials” are independent with probability $1/2$ of a
boy, and that they are fertile enough to keep producing children
indefinitely. What is the expected number of children?

So the answer and explanation provided in the book are as followed:

Let X be the number of children needed, starting with the 2nd child,
to obtain one whose gender is not the same as that of the firstborn.
Then $X - 1$ is $Geom(1/2)$, so $E(X) = 2$. This does not include the
firstborn, so the expected total number of children is $E(X + 1) = E(X) + 1 = 3$

I have two question regarding this:

*

*Is my approach for the question also correct? Or it shouldn't be that way?


Let X be the number of children needed, including the firstborn.
Therefore $X - 1 \sim Geom(1/2)$, but there are two possibility (i.e. first child is a boy, first child is a girl)
As a result, $E(X - 1) = 2$ (not sure how to explain this but by Geom(1/2) the expected value should be 1, while there are 2 possibilities so it becomes 2)
Geom(p) didn't include the "success" case, so we compute it back -> $E(X) = 2+1 = 3$



*Is the reason for the question setting X to be "starting from second child" to prevent getting 2 possibilities (like I did) and condition on whatever the first child's gender is. Or if anyway can explain the logic behind the formal answer as I am not really sure how the story goes.

Thanks a lot!
EDIT: suddenly one more approach here (Linearity of expectation), is it also valid?

Expectation of having the first child = 1 (regardless of boy/girl)
Expectation of having a child of a specific gender = 2 (we need a specific gender that is the opposite sex of the first child)
By linearity = 1+2 = 3

 A: It's best to construct Markov chain with 3 states:
1)State $\emptyset$, you start in it: no children.
2)State $1$. It doesn't matter which gender the very first kid is, so $P_{\emptyset,1}=1$
3)State 2. You get there when you have a child of a differet gender. Obvisouly $p_{1,2}=\frac{1}{2}$. It's an absorbing state: once you get there you stay there forever.
So you need to solve the following set of recurrent expressions for the mean first hitting time:
$$
m_{\emptyset, 2} = 1+ 1 m_{1,2}\\
m_{1,2} = 1+\frac{1}{2}m_{1,2} + \frac{1}{2}m_{2,2}
$$
which is trivial given $m_{2,2}=0$
A: Another recursive approach: let $g_t$ be the gender in trial $t$ and $e$ be the expected number of trials excluding the first child.
The intuition is this: you do one trial, if the genders are different, then stop, otherwise continue (accumulating the trials).
$$
e = \Pr(g_{t+1} \neq g_{t}) \cdot 1 + \Pr(g_{t+1} = g_{t}) \cdot(1 + e)
$$
where $\Pr(g_t \neq g_{t+1}) = \Pr(g_t = g_{t+1}) = \frac{1}{2}$
We have:
$$
\begin{align*}
e &= \frac{1}{2} + \frac{1}{2}\cdot(1+e) \\
2e &= 1 + 1+e \\
e &= 2 
\end{align*}
$$
Now, accounting for the first child, we obtain $E[X] = 1 + e = 3$.
A: Your approach is rather confusing - and I don't think it accounts correctly for how to handle two cases (adding one is certainly not the justifiable way!). It might be clearer to consider that the couple can be in one of four meaningful "states":
State 1: They have no children.
State 2a: They have a male child.
State 2b: They have a female child.
State 3: They have both.
Then, you can work out that from state 2a, they have, with each additional child, a $50\%$ chance of reaching state 3 and otherwise remain in state 2a - hence the expected time it takes them to get from state 2a to state 3 is expectation of $\operatorname{Geom}(1/2)$ - which is $2$.
Since the probability here is $1/2$, you can say the exact same thing about state 2b. So we know that the expected time to get from state 2a or 2b to 3 is $2$.
From state 1 we know that we will get to state 2a with probability $50\%$ and to state 2b with probability $50\%$ after one child. You can therefore figure out that the expected amount of time to get from state 1 to state 3 is the following:
\begin{align*}&(\text{probability of state 2a after one child})\,\times\,(\text{expected time 2a -> 3}) \\+\,& (\text{probability of state 2b after one child})\,\times\,(\text{expected time 2b -> 3})\\+\,&1\end{align*}
where the $+1$ arises from the fact that we are looking at what happens after one child. Given that state 2a and 2b turn out to have the same expected time and we always end up in exactly one of them, this just reduces to $2+1=3$, but using the more general formula, you can work out what happens if the probability were weighted towards one sex or the other. The answer from the book starts by realizing that this simplification would happen and simplifying way earlier, but there's no reason you couldn't handle both cases and then combine them at the end via this formula.
(In much much greater generality, this approach is a lot like the Markov chain idea mentioned in another answer - so it's worth connecting this sort of reasoning to that should you come across Markov chains, but understanding Markov chains is not a prerequisite to understanding this problem)
