N keys and N locks at once

304 Views Asked by At

There are $N$ keys and $N$ locks. We test all keys at once.

What is the probability that $k$ keys are correctly matched to $k$ locks ($k \leq n$)?

Thanks a lot!

1

There are 1 best solutions below

0
On

The number of permutations in $S_n$ which have $k$ fixed points will be $\binom{n}{k}\cdot !(n-k)$ where the subfactorial symbol $!r$ is in reference to the number of derangements of $r$ objects.

Assuming that exactly one key is tested per lock, we have then a probability getting exactly $k$ of the matching keys to their corresponding locks as being

$$\dfrac{!(n-k)\binom{n}{k}}{n!}$$