$n$ letters in $n$ envelopes A secretary introduces randomly 9 letters in 9 envelopes. Let $X$ be the random variable representing the number of letters that have matched the correct envelopes. Find $E(X)$ and $var(X)$
I know the solution for "the probability that none is in the correct envelope" and "the probability that at least one is in the correct envelope", but I don't know how to solve this.
 A: For $i=1,2,\dots,9$ let $X_i$ take value $1$ if letter $i$ lands in the correct envelop and let it take value $0$ otherwise.
Then:$$X=\sum_{i=1}^9X_i$$
With linearity of expectation and symmetry we find:$$\mathsf EX=\sum_{i=1}^9\mathsf EX_i=9\mathsf EX_1$$
Can you find $\mathsf EX_1$ yourself?
Further on base of bilinearity of covariance and symmetry we find:$$\mathsf{Var}(X)=\mathsf{Cov}(X,X)=\sum_{i=1}^9\sum_{j=1}^9\mathsf{Cov}(X_i,X_j)=9\mathsf{Cov}(X_1,X_1)+72\mathsf{Cov}(X_1,X_2)$$
Can you find $\mathsf{Cov}(X_1,X_1)=\mathsf{Var}(X_1)$ and $\mathsf{Cov}(X_1,X_2)$ yourself?
A: To build a permutation that fixes $k$ elements, you have to first choose these $k$ elements:
$${9\choose k }\text{ options}$$
Then you have to choose a derangement of the remaining $9-k$:
$$!(9-k)\text{ options}$$
The expected value is therefore $$E=\sum_\limits{k=0}^9k\times\dfrac{ !(9-k)\times {9\choose k }}{9!}$$
and the variance $$\left(\sum_\limits{k=0}^9k^2\times\dfrac{ !(9-k)\times {9\choose k }}{9!}\right)-E^2$$
