Analyzing the Hiring Problem, Generating Random Permutations




CS255

Chris Pollett

Jan 29, 2018

Outline

Introduction

Conditional Probability and Independence

Discrete Random Variables

Expectation and Variance

Indicator Random Variables

Example

Lemma 5.1

Given a sample space `S` and an event `A in S`, let `X_A=I{A}`. Then `E[X_A]=Pr{A}`.

Proof: `E[X_A] = E[I{A}] = 1 cdot Pr{A} + 0 cdot Pr{bar(A)} = Pr{A}`.

More Indicator Variables

Analysis of the Hiring Problem

More analysis of hiring problem

Lemma. Assume that the candidates are presented in random order, then algorithm Hire-Assistant has a hiring cost of `O(c_h ln n)`.

Proof. From before hiring cost is `O(m cdot c_h)` where `m` is the number of candidates hired. From the previous slide this is `O(ln n)`.

Finishing up the Hiring Problem

Quiz

Which of the following statements is true?

  1. The Hire-Assistant(n) algorithm only interviews half of the available candidates.
  2. The Hire-Assistant(n) algorithm always hires half of the available candidates.
  3. A distribution is a special kind of function from subsets of a sample space to the interval `[0, 1]`.

Randomly Permuting Arrays (Method 1)

Analyzing Method 1

Lemma. Procedure Permute-By-Sorting produces a uniform random permutation of the input, assuming that the priorities are distinct.

Proof. Let `sigma:[1 .. n] ->[1..n]` be a permutation, `sigma(i)` being where `i` goes under this permutation. Let `X_i` be the indicator that `A[i]` receives the `sigma(i)`th smallest priority. That is, it indicates that `i` will be mapped correctly after sorting by priorities. So if `X_i` holds then after sorting the element original value `i` stored in `A[i]` gets mapped to `A[sigma(i)]`. By the definition of conditional probability,
`Pr{Y|X} = (Pr{X cap Y})/(Pr{X})`, so `Pr{X cap Y} = Pr{X} cdot Pr{Y|X}`.
Using this, we have
`Pr{X_1 cap ... cap X_n} = Pr{X_1 cap ... capX_(n-1)} cdot Pr{X_n | X_1 cap ... cap X_(n-1)}`.
Continuing to expand, we get: `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)}`.
We can now fill in some of these values:
`Pr{X_1} = 1/n = ` probability that first priority chosen out of `n` is `sigma(1)`th smallest.
`Pr{X_i|X_1 cap... cap X_(i-1)} = 1/(n - i + 1)`.
This is because of the remaining elements `i`, `i+1`, ... `n`, each is equally likely to be the `sigma(i)`th smallest. So
`Pr{X_1 cap ... cap X_n} = 1/n cdot 1/(n-1) cdot ... cdot 1/2 cdot 1/1 = 1/(n!)`.
As `sigma` was arbitrary, any permutation is equally likely.

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`