So a guy attempts to open his front door with his $n$ keys, but of course only one key is right. If he eliminates incorrect keys as he goes, so he never tries a key more than once, find the expected value and the variance of the number of attempts required to open the door.
X: random variable of the number of attempts to open door
$x \in {1,2,3, ... , n}$ and $p(x) = \frac{1}{(n+1)-x}$
- Expected Value
$$E(X)=\sum_{x=1}^n xp(x)$$
$$=\sum_{x=1}^n x\frac{1}{(n+1-x)}$$
$$=\frac{-1}{6n(2n^2+3n-2)}$$
... Wolfram Alpha sum calculator ... https://www.wolframalpha.com/widget/widgetPopup.jsp?p=v&id=29c546473e1c796d6076bb18901b15e7&i0=4133000%20
Question: Where is my mistake?
Update:
Ok, so it should be $$=\sum_{x=1}^n x\frac{1}{n}$$ because, if I consider previous the failures of previous attempts, $$=1\frac{1}{n} + 2(\frac{n-1}{n})(\frac{1}{n-1}) + 3(\frac{n-1}{n})(\frac{n-2}{n-1})(\frac{1}{n-2}) ... $$ $$=\frac{1}{n}+2(\frac{1}{n}) + 3(\frac{1}{n}) ... $$ $$=\sum_{x=1}^n x\frac{1}{n}$$ $$=(\frac{1}{n})(\frac{n(n+1)}{2})$$
Is this right?
Therefore, $$E(x) = \frac{n+1}{2} and$$ $$Var(X)=\frac{n^2-1}{12}$$
If the guy randomly sorts the keys and then tries them in the sorted order, the probability that the correct key is at position $x$ is $P(X=x)=\frac{1}{n}$. If you want to calculate the probability using the conditional probabilities for the first $x-1$ attempts to fail, you will of course receive the same result: $$P(X=x) = \cfrac{1}{n+1-x}\prod_{k=1}^{x-1}\cfrac{n-k}{n+1-k} = \cfrac{1}{n+1-x}\cfrac{\prod_{k=1}^{x-1}(n-k)}{\prod_{k=1}^{x-1}(n+1-k)}=\cfrac{\prod_{k=2}^{x}(n+1-k)}{\prod_{k=1}^{x}(n+1-k)} = \cfrac{1}{n}$$ Therefore, $$ E(X) = \sum_{x=1}^{n}x\frac{1}{n} = \frac{n(n+1)}{2}\cdot\frac{1}{n} = \frac{n+1}{2}$$ Maybe this helps?