Random Permutations, the Birthday Problem, Ball and Bins Arguments




CS255

Chris Pollett

Feb 2, 2022

Outline

Introduction

More on Method 1

Claim. The probability that all the priorities are unique is at least 1- 1/n.

Proof. Let `X_i` be the indicator that the `i`th priority was unique. Again,
`Pr{X_1 cap ... cap X_n} = Pr{X_1} cdot Pr{X_2|X_1} cdots Pr{X_n | X_1 cap ... cap X_(n-1)}`.
`= n^3/n^3 cdot (n^3 -1)/n^3 cdots (n^3 - (n-1))/n^3`
`ge (n^3 -n)/n^3 cdot (n^3 -n)/n^3 cdots (n^3 -n)/n^3`
`= (1 - 1/n^2)^(n-1)`
`ge 1 - (n-1)/n^2` as `(1-a)(1-b) > 1 - a - b` if `a` and `b` nonnegative.
`> 1 - 1/n`

Randomly Permuting Arrays (Method 2)

Randomize-In-Place(A) 
1. n := length[A]
2. for i :=1 to n
3.     swap(A[i], A[Random(i,n)])

Analysis of Method 2

Lemma. Just prior to the ith iteration of the for loop, for each possible `(i-1)`-permutation, the subarray `A[1,i-1]` contains this permutation with probability `((n-i+1)!)/(n!)`

Proof. By induction on `i`.

Base case: When `i=1`, `A[1..0]` is the empty array. It is supposed to contain a given 0-permutation with probability `((n-1+1)!)/(n!) = (n!)/(n!)=1`. As a `0`-permutation has no elements and there is only one of them this is true.

Induction step: Assume just before the `i`th iteration, each `(i-1)`-permutation occurs in `A[1..i-1]` with probability `((n-i+1)!)/(n!)`. A particular, `i`-permutation `langle x_1,...,x_(i-1), x_i rangle` consists of an `(i-1)`-permutation followed by `x_i`. By the induction hypothesis, the probability of the `i`-permutation is thus
`[((n-i+1)!)/(n!)] cdot Pr{A[i]= x_i| A[1..i-1] = langle x_1,...,x_(i-1) rangle}`.
The second factor is `1/(n-i+1)` since by line 3 of Randomize-in-Place, `x_i` is choosen at random from `A[i..n]`. So the probability of the `i`-permutation is
`((n-i+1)!)/(n!) cdot 1/(n-i+1) = ((n-i)!)/(n!)` as desired.

More Analysis of Method 2

Theorem. Randomize-In-Place produces a uniformly chosen random permutation.

Proof. The program could generate any `n`-permutation. Further it terminates just before its `(n+1)`st iteration and thus by the lemma generates a given random `n`-permutation with probability:
`((n - (n+1) +1)!)/(n!) = (0!)/(n!) = 1/(n!)`
as desired.

In-Class Exercise

The Birthday Problem

How many people must there be in a room before there is a `50%` chance that two were born on the same day of the year?

More on the Birthday Problem

Number of Expected Shared Birthdays