taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 1.2.10-8

Exercise 1.2.10-8

not stated yet in Lean solution written

RatingM20
MarkersM (mathematical)
KindK3, find a value: compute a number, a set or a closed form from the written solution
SectionSection 1.2.10 of Volume 1. Companion chapter: Analysis of an algorithm

The task

Find the probability that nn keys, each chosen at random from MM values, are all distinct.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

Count the favorable lists and divide by MnM^n.

Solution

Show the solution

There are MnM^n equally likely lists (X[1],…,X[n])(X[1],\ldots,X[n]). A list with distinct entries is chosen by taking X[1]X[1] in MM ways, X[2]X[2] in M−1M-1 ways, and so on:

Pr⁡(all distinct)=M(M−1)⋯(M−n+1)Mn=M!(M−n)! Mn(n≤M),\Pr(\text{all distinct})=\frac{M(M-1)\cdots(M-n+1)}{M^n}=\frac{M!}{(M-n)!\,M^n}\quad(n\le M),

and the probability is 00 for n>Mn>M. For fixed nn it tends to 11 as M→∞M\to\infty, because each factor (M−j)/M→1(M-j)/M\to1.

Check

For M=365M=365 and n=23n=23 the value is 0.4927…0.4927\ldots (the birthday problem). For M=4M=4, n=3n=3 it is 4⋅3⋅264=38\frac{4\cdot3\cdot2}{64}=\frac38.

Remarks

The next exercise counts lists with exactly mm distinct values. The case m=nm=n is this one.

This solution is drafted, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.