CSCE 411 Lecture 27

From Notes
Jump to navigation Jump to search
Lecture Slides

« previous | Wednesday, October 31, 2012 | next »

Happy Halloween

Hiring Problem

You need to hire a new employee

The headhunter sends a different applicant every day for n days.

If the applicant is better than the current employee then fire the current employee and hire the applicant.

Firing and hiring is expensive.

How expensive is the whole process?

Analysis

The worst case is when headhunter sends all n applicants in increasing order of goodness: hire (and fire) each one in turn (n times)

Best case is when headhunter sends best applicant on the first day: hire just once.

Expected cost is E[X], where X is the number of applicants that are hired.


Change viewpoint: let Xi be the indicator random variable representing whether the ith applicant is hired (1 if hired, 0 otherwise).

Therefore X=i=1nXi and E[Xi]=Pr[applicant i is hired].

The probability that a person will be hired is 1i since out of the first i applicants potentially hired, there is one best candidate.

lnni=1n1iln(n+1)


Stop for quiz


Probablistic Analysis v. Randomized Algorithm

Probabilistic analysis assumes some sort of probability distribution on the inputs

Randomized algorithm makes random choices in computing the value of the algorithm.

Generating Random Permutations

class Array
  def shuffle
    1.upto(@size) do |i|
      j = (i..n).sample  # random value between i and n
      self[i], self[j] = self[j], self[i]
    end
  end
end


Analysis

Proposition. A[1..i] equals each permutation of i elements from {1,,n} with probability (ni)!n!.

Proof by Induction. Basis. After first iteration, A1 contains each permutation of 1 element from {1,,n} with probability (n1)!n!=1n

Induction. Assume that after (i1)st iteration of the loop the proposition holds. The probability that A[1..i] contains permutation x1,x2,,xi is the probability that A[1..i1] contains x1,x2,,xi after the (i1)st iteration and that the ith iteration puts xi in Ai

Let e1 be the event that A[1..i1] contains x1,x2,,xi1 after the (i1)st iteration.

Let e2 be the event that the ith iteration puts xi in Ai. We need to show that Pr[e1e2]=(ni)!n!.

e1 and e2 are not independent: if some element appears in A[1..i1], then it isn't available to appear in Ai

Pr[e1e2]=Pr[e2e1]Pr[e1]Pr[e2e1]=1ni+1Pr[e1]=(n(i1))!n! by inductive hypothesisPr[e1e2]=1ni+1(n(i1))!n!=(ni)!n!

Note in the second step, Pr[e2e1]=1ni+1 because xi is available in A[i..n] to be chosen since e1 already occurred and did not include xi and every element in A[i..n] is equally likely to be chosen.

Therefore, the algorithm gives us a uniform random permutation.

Q.E.D.