Download presentation
Presentation is loading. Please wait.
Published byNathaniel Lambert Modified over 9 years ago
1
Probabilistic Analysis and Randomized Algorithm
2
Worst case analysis Probabilistic analysis Need the knowledge of the distribution of the inputs Indicator random variables Given a sample space S and an event A, the indicator random variable I { A } associated with event A is defined as:
3
E.g.: Consider flipping a fair coin: Sample space S = { H, T } Define random variable Y with Pr { Y = H } = Pr { Y = T }= 1/2 We can define an indicator r.v. X H associated with the coin coming up heads, i.e. Y=H
5
Hire-Assistant(n) 1. best = 0 2. for i = 1 to n 3. interview candidate i 4. if candidate i is better than candidate best 5. best = i 6. hire candidate i
7
Randomized-Hire-Assistant(n) 1. randomly permute the list of candidate 2. best = 0 3. for i = 1 to n 4. interview candidate i 5. if candidate i is better than candidate best 6. best = i 7. hire candidate i
9
Permute-By-Sorting(A) 1. n = A.length 2. Let P[1..n] be a new array 3. for i = 1 to n 4. P[i] = Random(1, n^3) 5. sort A, using P as sort keys After sorting, if P[i] is the j-th smallest one, then A[i] lies in position j of the output.
11
Define event E i : A[i] receives the i -th smallest element. Pr{E 1 ∩ E 2 ∩ … ∩ E n-1 ∩ E n } = Pr{E 1 } Pr{E 2 |E 1 } Pr{E 3 |E 1 ∩ E 2 } … Pr{E n |E 1 ∩ E 2 ∩ … ∩ E n- 1 } Pr{E 1 }=1/n, Pr{E 2 |E 1 }=1/(n-1) Pr{E i |E 1 ∩ E 2 ∩ … ∩ E i-1 } = 1/(n-i+1) Pr{E 1 ∩ E 2 ∩ … ∩ E n-1 ∩ E n } = 1/n!, which is the probability of obtaining the identity permutation. It holds for any permutation.
12
Randomize-In-Place(A): a better method 1. n = A.length 2. for i = 1 to n 3. swap A[i] with A[Random(i, n)] Lemma: The above procedure computes a uniform random permutation.
13
The birthday paradox: How many people must there be in a room before there is a 50% chance that two of them born on the same day of the year? (1) Suppose there are k people and there are n days in a year, b i : i -th person’s birthday, i = 1,…, k Pr { b i =r } =1/n, for i = 1,…, k and r=1,2,…,n Pr { b i =r, b j =r }= Pr { b i =r } . Pr { b j =r } = 1/n 2
14
Define event A i : Person i ’s birthday is different from person j ’s for j < i Pr{B k } = Pr{B k-1 ∩ A k } = Pr{B k-1 }Pr{A k |B k-1 } where Pr{B 1 } = Pr{A 1 }=1
15
(2) Analysis using indicator random variables For each pair (i, j) of the k people in the room, define the indicator r.v. X ij, for 1≤ i < j ≤ k, by
16
When k(k-1) ≥ 2n, the expected number of pairs of people with the same birthday is at least 1
17
Balls and bins problem: Randomly toss identical balls into b bins, numbered 1,2,…,b The probability that a tossed ball lands in any given bin is 1/b (a) How many balls fall in a given bin? If n balls are tossed, the expected number of balls that fall in the given bin is n/b (b) How many balls must one toss, on the average, until a given bin contains a ball? By geometric distribution with probability 1/b
18
(c) (Coupon collector’s problem) How many balls must one toss until every bin contains at least one ball? Want know the expected number n of tosses required to get b hits The i th stage consists of the tosses after the (i-1) st hit until the i th hit For each toss during the i th stage, there are i-1 bins that contain balls and b-i+1 empty bins Thus, for each toss in the i th stage, the probability of obtaining a hit is (b-i+1)/b Let n i be the number of tosses in the i th stage. Thus the number of tosses required to get b hits is n= ∑ b i=1 n i Each n i has a geometric distribution with probability of success (b-i+1)/b → E[n i ]=b/b-i+1
19
Streaks Flip a fair coin n times, what is the longest streak of consecutive heads?Ans:θ(lg n) Let A ik be the event that a streak of heads of length at least k begin s with the i th coin flip For j=0,1,2,…,n, Let L j be the event that the longest streak of heads has Length exactly j, and let L be the length of the longest streak.
21
We look for streaks of length s by partitioning the n flips into approximately n/s groups of s flips each.
22
The probability that a streak of heads of length does not begin in position i is s ss n
24
Using indicator r.v. :
25
If c is large, the expected number of streaks of length clgn is very small. Therefore, one streak of such a length is very likely to occur.
26
The on-line hiring problem: To hire an assistant, an employment agency sends one candidate each day. After interviewing that person you decide to either hire that person or not. The process stops when a person is hired. What is the trade-off between minimizing the amount of interviewing and maximizing the quality of the candidate hired?
27
What is the best k?
28
Let M(j) = max 1 i j {score(i)}. Let S be the event that the best-qualified applicant is chosen. Let S i be the event the best-qualified applicant chosen is the i-th one interviewed. S i are disjoint and we have Pr{S}= j i=1 Pr{S i }. If the best-qualified applicant is one of the first k, we have that Pr{S i }=0 and thus Pr{S}= j i=k+1 Pr{S i }.
29
Let B i be the event that the best-qualified applicant must be in position i. Let O i denote the event that none of the applicants in position k+1 through i-1 are chosen If S i happens, then B i and O i must both happen. B i and O i are independent! Why? Pr{S i } = Pr{B i O i } = Pr{B i } Pr{O i }. Clearly, Pr{B i } = 1/n. Pr{O i } = k/(i-1). Why??? Thus Pr{S i } = k/(n(i-1)).
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.