Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


A dealership has $n$ cars. An employee with a sense of humor takes all $n$ keys, puts one of them in each car at random, then locks the doors of all cars. When the owner of the dealership discovers the problem, he calls a locksmith. He tells him to break into a car, then use the key found in that car to open another, and so on. If and when the keys already recovered by this procedure cannot open any new cars, the locksmith is to break into another car. This algorithm goes on until all cars are open.

(a) What is the probability that the locksmith will only have to break into one car?

(b) What is the probability that the locksmith will have to break into two cars only?

share|cite|improve this question
Welcome to math.SE: since you are fairly new, I wanted to let you know a few things about the site. In order to get the best possible answers, it is helpful if you say in what context you encountered the problem, and what your thoughts on it are so far; this will prevent people from telling you things you already know, and help them write their answers at an appropriate level. – Arturo Magidin Apr 9 '12 at 20:28

HINTS: Number the cars from $1$ to $n$ arbitrarily. Give each key the same number as the car to which it belongs. The employee’s prank results in a permutation $\pi$ of $\{1,\dots,n\}$ in which Car $k$ contains Key $\pi(k)$. Write $\pi$ as a product of disjoint cycles.

Now say that the locksmith initially breaks into Car $1$; he will then be able to get into every car whose number is in the cycle containing $1$. Thus, he will need to break into only one car if and only if the permutation is a cycle. Similarly, he will need to break into two cars if and only if the permutation is a product of two disjoint cycles.

  1. How many permutations of $\{1,\dots,n\}$ are there?

  2. How many of them are cycles?

  3. How many of them are a product of two disjoint cycles?

Added: Here’s a little more help with the third question. To get a permutation with two cycles, you have to split $\{1,\dots,n\}$ into two non-empty subsets. Then you have to order each of these subsets to make it a cycle. You already know from (2) how many ways there are to order a set as a single cycle. Be a little careful, though: $(135)(24)$ and $(24)(135)$ are the same permutation.

share|cite|improve this answer
1. I believe there are n! permutation as total and 2. in the one cycle (n-1)! and 3. in the two disjoint cycle... I really not sure – user28699 Apr 10 '12 at 17:45
@user28699: You’re right about (1) and (2). I’ve added a little more help with (3). – Brian M. Scott Apr 10 '12 at 21:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.