Let \(X\) be a random variable that is equal to the number of heads in two flips of a fair coin. What is \(\text{E}[X^2]\)? What is \(\text{E}^2[X]\)?

This exercise tests understanding of expected values and the difference between \(\text{E}[X^2]\) and \((\text{E}[X])^2\).

With two coin flips, \(X\) can be 0 (TT, probability \(1/4\)), 1 (HT or TH, probability \(1/2\)), or 2 (HH, probability \(1/4\)). The expected number of heads is:

\[\begin{align*} \text{E}[X] &= 0 \cdot \frac{1}{4} + 1 \cdot \frac{1}{2} + 2 \cdot \frac{1}{4} = 1 \end{align*}\]

This makes intuitive sense: on average, we expect 1 head in 2 flips.

The expected value of \(X^2\) is:

\[\begin{align*} \text{E}[X^2] &= 0^2 \cdot \frac{1}{4} + 1^2 \cdot \frac{1}{2} + 2^2 \cdot \frac{1}{4} \\ &= 0 + \frac{1}{2} + 1 = \frac{3}{2} \end{align*}\]

And the square of the expected value is:

\[\text{E}^2[X] = (\text{E}[X])^2 = 1^2 = 1\]

So \(\text{E}[X^2] = 3/2\) and \(\text{E}^2[X] = 1\). Note that \(\text{E}[X^2] \neq \text{E}^2[X]\) in general. The difference \(\text{E}[X^2] - \text{E}^2[X]\) is the variance of \(X\), which measures how spread out the distribution is.