Random Permutations, the Birthday Problem, Ball and Bins Arguments




CS255

Chris Pollett

Feb 2, 2015

Outline

Introduction

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 the `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.

Quiz

Which of the following is true?

  1. It is possible to have a probability distribution in which all events are assigned probability 0.
  2. The expected value of an indicator random variable `X` is `Pr{X=1}`.
  3. Generating priorities randomly as we did in class last week in the range 1 to `n^3`, we showed it was impossible to ever get the same priority twice.

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

Balls and Bins

Ball and Bin Questions

We can ask a variety of questions about the ball tossing process. As a first question, we ask:

How many balls fall in a given bin?

Second Ball and Bin Question

How many balls must one toss on average, until a given bin contains a ball?

Third Ball and Bin Question

How many balls must one toss on average, until every bin contains at least one ball?