Finding $\mathbb{E}(N^2)$ where $N$ is number of tosses until we get a head Here's a question from my probability textbook:

Suppose we toss a fair coin, and let $N$ denote the number of tosses until we get a head (including the final toss). What is $\mathbb{E}(N)$ and $\mathbb{E}(N^2)$?

I got that $\mathbb{E}(N) = 2$ from the equation$$\mathbb{E}(N) = {1\over2} + {1\over2}(\mathbb{E}(N) + 1).$$But how do I derive that $\mathbb{E}(N^2) = 6$?
 A: Work out:$$\mathbb E[N^2]=\frac12\cdot1^2+\frac12\mathbb E[(1+N)^2]$$
A: The reasoning for the equation you wrote for $\mathbb E[N]$ is that the first toss is heads with probability $1/2$, in which case the expected number of tosses is $1$; otherwise, it is tails with probability $1/2$ in which case the expected number of tosses to get heads is $\mathbb E[N+1] = \mathbb E[N] + 1$ because the first toss was a failure.  Hence $$\mathbb E[N] = \frac{1}{2} \cdot 1 + \frac{1}{2} \cdot (\mathbb E[N] + 1),$$ by the law of total probability.
We employ the same reasoning for $\mathbb E[N^2]$.  If the first toss is heads with probability $1/2$, then the square of the number of tosses is $1^2 = 1$; otherwise, it is tails with probability $1/2$ and the expected number of the square of tosses is $$\mathbb E[(N+1)^2] = \mathbb E[N^2] + 2\mathbb E[N] + 1.$$  Therefore
$$\mathbb E[N^2] = \frac{1}{2} \cdot 1^2 + \frac{1}{2} \cdot (\mathbb E[N^2] + 2\mathbb {E}[N] + 1) = \frac{1}{2} + \frac{1}{2} (\mathbb {E}[N^2] + 2 \cdot 2 + 1) = 3 + \frac{\mathbb E[N^2]}{2}.$$  This yields $\mathbb E[N^2] = 6$.
