BY Lecturer: Aisha Dawood. The hiring problem:  You are using an employment agency to hire a new office assistant.  The agency sends you one candidate.

Slides:



Advertisements
Similar presentations
Lecture Discrete Probability. 5.3 Bayes’ Theorem We have seen that the following holds: We can write one conditional probability in terms of the.
Advertisements

Review of Probability. Definitions (1) Quiz 1.Let’s say I have a random variable X for a coin, with event space {H, T}. If the probability P(X=H) is.
Analysis of Algorithms CS Data Structures Section 2.6.
Analysis of Algorithms
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 6.
Theory of Computing Lecture 3 MAS 714 Hartmut Klauck.
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Dr. Sumanta Guha Slide Sources: CLRS “Intro.
1 Today’s Material Medians & Order Statistics – Ch. 9.
CPSC 411, Fall 2008: Set 10 1 CPSC 411 Design and Analysis of Algorithms Set 10: Randomized Algorithms Prof. Jennifer Welch Fall 2008.
Section 7.4 (partially). Section Summary Expected Value Linearity of Expectations Independent Random Variables.
April 2, 2015Applied Discrete Mathematics Week 8: Advanced Counting 1 Random Variables In some experiments, we would like to assign a numerical value to.
Probabilistic Analysis and Randomized Algorithm. Worst case analysis Probabilistic analysis  Need the knowledge of the distribution of the inputs Indicator.
Chapter 5. Probabilistic Analysis and Randomized Algorithms
UMass Lowell Computer Science Analysis of Algorithms Spring, 2002 Chapter 5 Lecture Randomized Algorithms Sections 5.1 – 5.3 source: textbook.
CSE 2331/5331 Topic 5: Prob. Analysis Randomized Alg.
Probabilistic (Average-Case) Analysis and Randomized Algorithms Two different approaches –Probabilistic analysis of a deterministic algorithm –Randomized.
Analysis of Algorithms CS 477/677 Randomizing Quicksort Instructor: George Bebis (Appendix C.2, Appendix C.3) (Chapter 5, Chapter 7)
1 Hiring Problem and Generating Random Permutations Andreas Klappenecker Partially based on slides by Prof. Welch.
Probabilistic (Average-Case) Analysis and Randomized Algorithms Two different but similar analyses –Probabilistic analysis of a deterministic algorithm.
Probabilistic Analysis and Randomized Algorithms
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu.
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
Tirgul 8 Universal Hashing Remarks on Programming Exercise 1 Solution to question 2 in theoretical homework 2.
Qsort - 1 Lin / Devi Comp 122 d(n)d(n) Today’s puzzle  How far can you reach with a stack of n blocks, each 2 units long?
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 5 Linear-time sorting Can we do better than comparison sorting? Linear-time sorting.
1 Randomized Algorithms Andreas Klappenecker [using some slides by Prof. Welch]
1 Discrete Probability Hsin-Lung Wu Assistant Professor Advanced Algorithms 2008 Fall.
Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner.
Computer Algorithms Lecture 11 Sorting in Linear Time Ch. 8
Ch. 8 & 9 – Linear Sorting and Order Statistics What do you trade for speed?
Lecture 2 We have given O(n 3 ), O(n 2 ), O(nlogn) algorithms for the max sub-range problem. This time, a linear time algorithm! The idea is as follows:
1 9/8/2015 MATH 224 – Discrete Mathematics Basic finite probability is given by the formula, where |E| is the number of events and |S| is the total number.
1 9/23/2015 MATH 224 – Discrete Mathematics Basic finite probability is given by the formula, where |E| is the number of events and |S| is the total number.
Randomized Algorithms (Probabilistic algorithm) Flip a coin, when you do not know how to make a decision!
Order Statistics The ith order statistic in a set of n elements is the ith smallest element The minimum is thus the 1st order statistic The maximum is.
The Selection Problem. 2 Median and Order Statistics In this section, we will study algorithms for finding the i th smallest element in a set of n elements.
Market Design and Analysis Lecture 5 Lecturer: Ning Chen ( 陈宁 )
CSCE 411 Design and Analysis of Algorithms Set 9: Randomized Algorithms Prof. Jennifer Welch Fall 2014 CSCE 411, Fall 2014: Set 9 1.
Introduction to Algorithms Jiafen Liu Sept
COMP 170 L2 L17: Random Variables and Expectation Page 1.
Chapter 5: Probability Analysis of Randomized Algorithms Size is rarely the only property of input that affects run time Worst-case analysis most common.
CSC401 – Analysis of Algorithms Lecture Notes 2 Asymptotic Analysis Objectives: Mathematics foundation for algorithm analysis Amortization analysis techniques.
Randomized Algorithms CSc 4520/6520 Design & Analysis of Algorithms Fall 2013 Slides adopted from Dmitri Kaznachey, George Mason University and Maciej.
Probabilistic Analysis and Randomized Algorithm. Average-Case Analysis  In practice, many algorithms perform better than their worse case  The average.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 7.
ICS 353: Design and Analysis of Algorithms
Introduction to Algorithms Randomized Algorithms – Ch5 Lecture 5 CIS 670.
Lecture 6 Dustin Lueker.  Standardized measure of variation ◦ Idea  A standard deviation of 10 may indicate great variability or small variability,
COSC 3101A - Design and Analysis of Algorithms 4 Quicksort Medians and Order Statistics Many of these slides are taken from Monica Nicolescu, Univ. of.
Master Method (4. 3) Recurrent formula T(n) = a  T(n/b) + f(n) 1) if for some  > 0 then 2) if then 3) if for some  > 0 and a  f(n/b)  c  f(n) for.
CSC317 1 Randomized algorithms Hiring problem We always want the best hire for a job! Using employment agency to send one candidate at a time Each day,
Introduction to Algorithms Probability Review – Appendix C CIS 670.
CSC317 1 Hiring problem-review Cost to interview (low C i ) Cost to fire/hire … (expensive C h ) n number of candidates m hired O (c i n + c h m) Independent.
Randomized Algorithms (Probabilistic algorithm) Flip a coin, when you do not know how to make a decision!
Theory of Computational Complexity Probability and Computing Ryosuke Sasanuma Iwama and Ito lab M1.
PROBABILITY AND COMPUTING RANDOMIZED ALGORITHMS AND PROBABILISTIC ANALYSIS CHAPTER 1 IWAMA and ITO Lab. M1 Sakaidani Hikaru 1.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Chapter 6: Discrete Probability
Applied Discrete Mathematics Week 11: Relations
CS 583 Analysis of Algorithms
CSCE 411 Design and Analysis of Algorithms
Chapter 5: Probabilistic Analysis and Randomized Algorithms
Topic 3: Prob. Analysis Randomized Alg.
Applied Discrete Mathematics Week 12: Discrete Probability
Programming with data Lecture 3
Chapter 5: Probabilistic Analysis and Randomized Algorithms
Randomized Algorithm & Public Key Cryptography
Randomized Algorithms
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Randomized Algorithms
Presentation transcript:

BY Lecturer: Aisha Dawood

The hiring problem:  You are using an employment agency to hire a new office assistant.  The agency sends you one candidate each day.  You interview the candidate and must immediately decide whether or not to hire that person. But if you hire, you must also fire your current office assistant even if it’s someone you have recently hired.  Cost to interview is ci per candidate (interview fee paid to agency).  Cost to hire is ch per candidate (includes cost to fire current office assistant + hiring fee paid to agency).  Assume that ch > ci.  You are committed to having hired, at all times, the best candidate seen so far. Meaning that whenever you interview a candidate who is better than your current office assistant, you must fire the current office assistant and hire the candidate. Since you must have someone hired at all times, you will always hire the first candidate that you interview. Goal: Determine what the price of this strategy will be. 2

Pseudocode to model this scenario: Assumes that the candidates are numbered 1 to n and that after interviewing each candidate, we can determine if it’s better than the current office assistant. Uses a dummy candidate 0 that is worse than all others, so that the first candidate is always hired. HIRE-ASSISTANT(n) best ← 0 candidate 0 is a least-qualified dummy candidate for i ← 1 to n do interview candidate i if candidate i is better than candidate best then best ←i hire candidate i Cost: If n candidates, and we hire m of them, the cost is O(nc i + mc h ). 3

 We Have to pay nc i to interview, no matter how many we hire.  So we focus on analyzing the hiring cost mc h.  mc h varies with each run. It depends on the order in which we interview the candidates.  Worst-case analysis  In the worst case, we hire all n candidates.  This happens if each one is better than all who came before. In other words, if the candidates appear in increasing order of quality.  If we hire all n, then the cost is O(nc i + nc h ) = O(nc h ) (since c h > c i ). 4

 In general, we have no control over the order in which candidates appear.  We could assume that they come in a random order: Assign a rank to each candidate: rank(i ) is a unique integer in the range 1 to n. The ordered list rank(1), rank(2),..., rank(n) is a permutation of the candidate numbers 1, 2,..., n. The list of ranks is equally likely to be any one of the n! permutations. Equivalently, the ranks form a uniform random permutation: each of the possible n! permutations appears with equal probability.  Essential idea of probabilistic analysis: We must use knowledge of, or make assumptions about, the distribution of inputs. The expectation is over this distribution. This technique requires that we can make a reasonable characterization of the input distribution. 5

 For the hiring problem:  Instead of relying on the candidates being presented to us in a random order, we take control of the process and enforce a random order.  What makes an algorithm randomized: An algorithm is randomized if its behavior is determined in part by values produced by a random-number generator. RANDOM(a, b) returns an integer r, where a ≤ r ≤ b and each of the b−a+1 possible values of r is equally likely. In practice, RANDOM is implemented by a pseudorandom-number generator 6

 A simple yet powerful technique for computing the expected value of a random variable.  Given a sample space and an event A, we define the indicator random variable 7 Lemma For an event A, let XA = I {A}. Then E [XA] = Pr {A}. Proof Letting A be the complement of A, we have E [XA] = E [I {A}] = 1 ・ Pr {A} + 0 ・ Pr {A} (definition of expected value) = Pr {A}.

 Simple example: Determine the expected number of heads when we flip a fair coin one time. Sample space is {H, T }. Pr {H} = Pr {T } = 1/2. Define indicator random variable XH = I {H}. XH counts the number of heads in one flip. Since Pr {H} = 1/2, lemma says that E[XH ] = 1/2.  Slightly more complicated example: Determine the expected number of heads in n coin flips. Let X be a random variable for the number of heads in n flips. Could compute E[X] = nk = n ・ Pr {X = k}. 8

 Assume that the candidates arrive in a random order.  Let X be a random variable that equals the number of times we hire a new office assistant.  Define indicator random variables X1, X2,..., Xn, where Xi = I {candidate i is hired}.  Useful properties:  X = X1 + X2 + ・ ・ ・ + Xn.  Lemma ⇒ E [Xi ] = Pr {candidate i is hired}.  We need to compute Pr {candidate i is hired}: ◦ Candidate i is hired if and only if candidate i is better than each of candidates 1, 2,..., i − 1. ◦ Assumption that the candidates arrive in random order ⇒ candidates 1, 2,..., i  arrive in random order ⇒ any one of these Þrst i candidates is equally likely to be the best one so far.  Thus, Pr {candidate i is the best so far} = 1/i.  Which implies E[Xi ] = 1/i. 9

(the sum is a harmonic series).  Thus, the expected hiring cost is O(c h ln n), which is much better than the worst case cost of O(nc h ). 10

 considers two methods of randomly permuting an n-element array:  The first method assigns a random priority in the range 1 to n 3 to each position and then reorders the array elements into increasing priority order.  The second method is better: it works in place (unlike the priority-based method), it runs in linear time without requiring sorting, and it needs fewer random bits (n random numbers in the range 1 to n rather than the range 1 to n 3 ). 11