# Expected Value of Matching $n$ Balls in $n$ Boxes [closed]

Lets say there is an experiment in which balls numbered $1,...,n$ are distributed at random in $n$ boxes, also numbered $1,...,n$ so that each box has exactly one ball. Thus, the total number of possible outcomes is $n!$. Let $S_n$ be the number of matches; a match occurs when the ball and the box containing it have the same number.

I want to find $E(S_n)$ and $Var(S_n)$. I'm having troubles identifying the problem mathematically.

## closed as off-topic by Henrik, Nick Peterson, Davide Giraudo, Daniel W. Farlow, zhorasterDec 20 '16 at 22:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question is missing context or other details: Please improve the question by providing additional context, which ideally includes your thoughts on the problem and any attempts you have made to solve it. This information helps others identify where you have difficulties and helps them write answers appropriate to your experience level." – Henrik, Nick Peterson, Davide Giraudo, Daniel W. Farlow, zhoraster
If this question can be reworded to fit the rules in the help center, please edit the question.

• I had an answer on my computer, but I had to go afk for a while. When I came back and finished up and submitted my answer, the question was closed. If you add some context, maybe the question will be reopened. – robjohn Dec 21 '16 at 2:49

Hint: If $X_i$ is the number of the ball in the $i$-th box, then $S_n = \sum \limits_{i = 1}^n I\{X_i = i\}$. Now use standard arithmetic and the linearity of the expectation to determine $E[S_n]$ and $E[S_n^2]$.
• So for $E[S_n]$ would it just be $(1/n!)^n$ and for $E[S^2_n]$ it would be the same? – Mike Dec 20 '16 at 16:16
• Here is how I did it $E[S_n]=E[I{X_1=1}+...+I{X_n=n}]$ then for each term multiply the value of 1 by the probability of $i-th$ ball getting in the corresponding bin which is $1/n$ – Mike Dec 20 '16 at 16:25
• Then how did you get from this to $1/n!^n$? – Dominik Dec 20 '16 at 16:25
• It should of been $(1/n)^n$ but I couldn't edit my comment. – Mike Dec 20 '16 at 16:27