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,

Slides:



Advertisements
Similar presentations
Beginning Probability
Advertisements

Lecture Discrete Probability. 5.3 Bayes’ Theorem We have seen that the following holds: We can write one conditional probability in terms of the.
Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Section 5.1 and 5.2 Probability
1 Counting. 2 Situations where counting techniques are used  You toss a pair of dice in a casino game. You win if the numbers showing face up have a.
Business Statistics for Managerial Decision
Probability Chapter Independent Events Section
Probability Sample Space Diagrams.
Random Variables and Expectation. Random Variables A random variable X is a mapping from a sample space S to a target set T, usually N or R. Example:
CPSC 411, Fall 2008: Set 10 1 CPSC 411 Design and Analysis of Algorithms Set 10: Randomized Algorithms Prof. Jennifer Welch Fall 2008.
8.7 Probability. Ex 1 Find the sample space for each of the following. One coin is tossed. Two coins are tossed. Three coins are tossed.
Section 7.4 (partially). Section Summary Expected Value Linearity of Expectations Independent Random Variables.
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.
1 Hiring Problem and Generating Random Permutations Andreas Klappenecker Partially based on slides by Prof. Welch.
Probabilistic Analysis and Randomized Algorithms
Random Variables A Random Variable assigns a numerical value to all possible outcomes of a random experiment We do not consider the actual events but we.
1 Copyright M.R.K. Krishna Rao 2003 Chapter 5. Discrete Probability Everything you have learned about counting constitutes the basis for computing the.
Expected Value.  In gambling on an uncertain future, knowing the odds is only part of the story!  Example: I flip a fair coin. If it lands HEADS, you.
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?
1 Randomized Algorithms Andreas Klappenecker [using some slides by Prof. Welch]
Bell Work: Factor x – 6x – Answer: (x – 8)(x + 2)
1 Discrete Probability Hsin-Lung Wu Assistant Professor Advanced Algorithms 2008 Fall.
Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner.
Sets, Combinatorics, Probability, and Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProbability.
Sets, Combinatorics, Probability, and Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProbability.
Randomized Algorithms (Probabilistic algorithm) Flip a coin, when you do not know how to make a decision!
Great Theoretical Ideas In Computer Science Steven Rudich, Anupam GuptaCS Spring 2004 Lecture 22April 1, 2004Carnegie Mellon University
Simple Mathematical Facts for Lecture 1. Conditional Probabilities Given an event has occurred, the conditional probability that another event occurs.
Counting and Probability. Counting Elements of Sets Theorem. The Inclusion/Exclusion Rule for Two or Three Sets If A, B, and C are finite sets, then N(A.
Applied Business Forecasting and Regression Analysis Review lecture 2 Randomness and Probability.
COMP 170 L2 L18: Random Variables: Independence and Variance Page 1.
Probability Distributions. Essential Question: What is a probability distribution and how is it displayed?
From Randomness to Probability
Chapter 1:Independent and Dependent Events
Random Variables. A random variable X is a real valued function defined on the sample space, X : S  R. The set { s  S : X ( s )  [ a, b ] is an event}.
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.
CSCE 411 Design and Analysis of Algorithms Set 9: Randomized Algorithms Prof. Jennifer Welch Fall 2014 CSCE 411, Fall 2014: Set 9 1.
Understanding Randomness
Chapter 5: Probability Analysis of Randomized Algorithms Size is rarely the only property of input that affects run time Worst-case analysis most common.
Randomized Algorithms CSc 4520/6520 Design & Analysis of Algorithms Fall 2013 Slides adopted from Dmitri Kaznachey, George Mason University and Maciej.
Class 2 Probability Theory Discrete Random Variables Expectations.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 From Randomness to Probability.
5.1 Probability in our Daily Lives.  Which of these list is a “random” list of results when flipping a fair coin 10 times?  A) T H T H T H T H T H 
5.1 Randomness  The Language of Probability  Thinking about Randomness  The Uses of Probability 1.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 7.
12/24/ Probability Distributions. 12/24/ Probability Distributions Random Variable – a variable whose values are numbers determined.
Probability Theory Modelling random phenomena. Permutations the number of ways that you can order n objects is: n! = n(n-1)(n-2)(n-3)…(3)(2)(1) Definition:
Introduction to Algorithms Randomized Algorithms – Ch5 Lecture 5 CIS 670.
11.7 Continued Probability. Independent Events ► Two events are independent if the occurrence of one has no effect on the occurrence of the other ► Probability.
Great Theoretical Ideas in Computer Science for Some.
Experiments, Outcomes and Events. Experiment Describes a process that generates a set of data – Tossing of a Coin – Launching of a Missile and observing.
ROLL A PAIR OF DICE AND ADD THE NUMBERS Possible Outcomes: There are 6 x 6 = 36 equally likely.
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.
Math 1320 Chapter 7: Probability 7.3 Probability and Probability Models.
Counting and Probability. Imagine tossing two coins and observing whether 0, 1, or 2 heads are obtained. Below are the results after 50 tosses Tossing.
Section 7.3. Why we need Bayes?  How to assess the probability that a particular event occurs on the basis of partial evidence.  The probability p(F)
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Equal costs at all levels
Introduction to Discrete Probability
Counting Principles Ex. Eight pieces of paper are numbered 1 to 8 and placed in a box. One piece of paper is drawn from the box, its number is written.
Conditional Probability
PROBABILITY.
CSCE 411 Design and Analysis of Algorithms
Investigation 2 Experimental and Theoretical Probability
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
NOTE 2: sample spaces There are a number of ways of displaying sample spaces: Listing outcomes 2-dimensional graphs Tree diagrams Venn diagrams.
Chapter 11 Probability.
Sets, Combinatorics, Probability, and Number Theory
Presentation transcript:

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, we interview one candidate We must decide immediately if to hire candidate and if so, fire previous Always want the best hire… Cost to interview (low) Cost to fire/hire… (expensive) In other words …

CSC317 2 Hire-Assistant(n) 1. best = 0 //least qualified candidate 2. for i = 1 to n 3. interview candidate i 4. if candidate i better than best 5. best = i 6. hire candidate i Always want the best hire… fire if better candidate comes along Cost to interview (low) C i Cost to fire/hire… (expensive) C h C h > C i n total number of candidates m total number of hires O (?)

CSC317 3 Hire-Assistant(n) 1. best = 0 //least qualified candidate 2. for i = 1 to n 3. interview candidate i 4. if candidate i better than best 5. best = i 6. hire candidate i Always want the best hire… fire if better candidate comes along Cost to interview (low) C i Cost to fire/hire… (expensive) C h C h > C i n total number of candidates m total number of hires O (?) different cost of hiring Not run time but cost of hiring, but flavor of max problem

CSC317 4 Always want the best hire… fire if better candidate comes along Cost to interview (low) C i Cost to fire/hire… (expensive) C h C h > C i n total number of candidates m total number of hires Different type of cost – not run time, but cost of hiring. But when is it most expensive? When candidates interview in reverse order, worst first… O (c i n + c h m)

CSC317 5 Hiring problem 1. best = 0 //least qualified candidate 2. for i = worst_candidate to best_candidate… O (c i n + c h n) = O(c h n) When is this most expensive? When candidates interview in reverse order, worst first…

CSC317 6 Always want the best hire… fire if better candidate comes along Cost to interview (low) C i Cost to fire/hire… (expensive) C h C h > C i n total number of candidates m total number of hires When is it least expensive?

CSC317 7 Hiring problem 1. best = 0 //least qualified candidate 2. for i = best_candidate to worst_candidate… O (c i n + c h ) When is this leat expensive? When candidates interview in order, best first… But we don’t know who is best a priori

CSC317 8 Hiring problem 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 of order of candidates depends on order of candidates What about if we randomly invite candidates?

CSC317 9 Hiring problem and randomized algorithms O (c i n + c h m) depends on order of candidates Can’t assume in advance that candidates are in random order – bias might exist. We can add randomization to our algorithm – by asking the agency to send names in advance and randomize

CSC Hiring problem - randomized We always want the best hire for a job! Employment agency sends list of n candidates in advance Each day, we choose randomly a candidate from the list to interview We do not rely on the agency to send us randomly, but rather take control in algorithm

CSC Randomized hiring problem(n) 1. randomly permute the list of candidates 2. Hire-Assistant(n) What do we mean by randomly permute (we need a random number generator)? Random(a,b) Function that returns an integer between a and b, inclusive, where each integer has equal probability Most programs: pseudorandom-number generator

CSC Including random number generator Random(a,b) Function that returns an integer between a and b, inclusive, where each integer has equal probability So, Random(0,1)? 0 with P = with P = 0.5

CSC Including random number generator Random(a,b) Function that returns an integer between a and b, inclusive, where each integer has equal probability So, Random(3,7)? 3 with P = with P = with P = with P = with P = 0.2 Like rolling a ( ) dice

CSC How do we random permutations? Randomize-in-place(A,n) 1. For i = 1 to n 2. swap A[i] with A[Random(i,n)] A = A = A = … i Random choice from A[i,…,n]

CSC Probability review Sample space S: space of all possible outcomes (e.g. that can happen in a coin toss) Probability of each outcome: p(i) ≥ 0 Example: coin toss S = {H, T}

CSC Probability review Event: a subset of all possible outcomes; subset of sample space S Probability of event: Example: coin toss that give heads E = {H} Example: rolling two dice

CSC Probability review Example: rolling two dice List all possible outcomes S={(1,1},(1,2),(1,3), …(2,1),(2,2),(2,3), …(6,6)} List the event or subset of outcomes for which the sum of the dice is 7 E = {(1,6),(6,1),(2,5),(5,2),(3,4),(4,3)} Probability of event that sum of dice 7: 6/36 = 1/6

CSC Probability review Random variable: attaches value to an outcome/s Example: value of one dice Example: sum of two dice P(X = x) : Probability that random variable X takes on value x random variable value of random variable P(X = x) : Probability that sum of two dice has value x, e.g. P(X = 7) = 1/6

CSC Probability review Expectation or Expected Value of Random Variables: Average sum over each possible values, weighted by probability of that value

CSC Easier way? Linearity of Expectation random variables, then: Does not require independence of random variables. Example: X 1 and X 2 represent the values of a dice

CSC Probability review Indicator Random Variable (indicating if occurs…) if A occurs vice versa Lemma: For event A Example: Expected number Heads when flipping fair coin

CSC Probability review Indicator Random Variable & Linearity of Expectation if A occurs vice versa Example: Expected number Heads when flipping 3 fair coins