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 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 applicants in increasing order of goodness: hire (and fire) each one in turn ( times)

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

Expected cost is , where is the number of applicants that are hired.


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

Therefore and .

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


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. equals each permutation of elements from with probability .

Proof by Induction. Basis. After first iteration, contains each permutation of 1 element from with probability

Induction. Assume that after st iteration of the loop the proposition holds. The probability that contains permutation is the probability that contains after the st iteration and that the th iteration puts in

Let be the event that contains after the st iteration.

Let be the event that the th iteration puts in . We need to show that .

and are not independent: if some element appears in , then it isn't available to appear in

Note in the second step, because is available in to be chosen since already occurred and did not include and every element in is equally likely to be chosen.

Therefore, the algorithm gives us a uniform random permutation.

Q.E.D.