The question I am trying to solve is finding the $\mathsf E(X^2)$ in the matching problem (Let $X$ be the total number of matches if there are $n$ letters and $n$ envelopes randomly matched, etc). I understand using the indicator variable method in order to find that $\mathsf E(X)=1$. I am having issues figuring out why $\mathsf E(X^2)=2$ so that $\mathsf {Var}(X)=\mathsf E(X^2)-(\mathsf E(X))^2 = 1$.
Any help is appreciated! Thanks.
Note that $X=\sum\limits_{i=1}^n X_i$ where $\{X_i\}_n$ are the indicators, and $\mathsf E(X_i)=\frac 1 n$ is the probability that an envelop matches its letter. Thus, $$ \begin{align}\mathsf E(X^2) & =\mathsf E\left(\sum_{i=1}^n X_i \sum_{j=1}^n X_j\right)\\[1ex] ~ & = \sum_{i=1}^n\mathsf E(X_i^2)+\mathop{\sum\sum}_{\substack{i\in\{1..n\}\\ j\in\{1..n\}\setminus\{i\}}}\mathsf E(X_iX_j) \\[1ex] ~ & = \frac n n +\frac{n(n-1)}{n(n-1)}\end{align} $$ Now, do you get why $\mathsf E(X_i^2)=\frac 1 n$ and why $\mathsf E(X_iX_j)=\frac 1 {n(n-1)}$ when $i\neq j$? (Hint: $X_i$ and $X_j$ are Bernouli indicator random variables.)