lecture 2-cs648
TRANSCRIPT
![Page 1: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/1.jpg)
Randomized AlgorithmsCS648
Lecture 2
• Randomized Algorithm for Approximate Median
• Elementary Probability theory
1
![Page 2: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/2.jpg)
RANDOMIZED MONTE CARLO ALGORITHM FOR
APPROXIMATE MEDIAN
2
This lecture was delivered at slow pace and its flavor was that of a tutorial.
Reason: To show that designing and analyzing a randomized algorithm demands right insight and just elementary probability.
![Page 3: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/3.jpg)
A simple probability exercise
3
![Page 4: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/4.jpg)
4
![Page 5: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/5.jpg)
Approximate median
Definition: Given an array A[] storing n numbers and ϵ > 0, compute an element whose rank is in the range [(1- ϵ)n/2, (1+ ϵ)n/2].
Best Deterministic Algorithm:
• “Median of Medians” algorithm for finding exact median
• Running time: O(n)
• No faster algorithm possible for approximate median
5
Can you give a short proof ?
![Page 6: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/6.jpg)
½ - Approximate medianA Randomized Algorithm
Rand-Approx-Median(A)
1. Let k c log n;
2. S ∅;
3. For i=1 to k
4. x an element selected randomly uniformly from A;
5. S S U {x};
6. Sort S.
7. Report the median of S.
Running time: O(log n loglog n)
6
![Page 7: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/7.jpg)
Analyzing the error probability of Rand-approx-median
7
Elements of A arranged in Increasing order of values
n/4 3n/4
Right QuarterLeft Quarter
When does the algorithm err ?To answer this question, try to characterize what
will be a bad sample S ?
![Page 8: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/8.jpg)
Analyzing the error probability of Rand-approx-median
Observation: Algorithm makes an error only if k/2 or more elements
sampled from the Right Quarter (or Left Quarter).
8
n/4
Left Quarter Right Quarter
Elements of A arranged in Increasing order of values
3n/4 Median of S
![Page 9: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/9.jpg)
Analyzing the error probability of Rand-approx-median
9
Elements of A arranged in Increasing order of values
n/4 3n/4
Right QuarterLeft Quarter
Exactly the same as the coin tossing exercise we did !
¼
![Page 10: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/10.jpg)
Main result we discussed
10
![Page 11: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/11.jpg)
ELEMENTARY PROBABILITY THEORY
(IT IS SO SIMPLE THAT YOU UNDERESTIMATE ITS ELEGANCE AND POWER)
11
![Page 12: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/12.jpg)
Elementary probability theory(Relevant for CS648)
• We shall mainly deal with discrete probability theory in this course.
• We shall take the set theoretic approach to explain probability theory.
Consider any random experiment :
o Tossing a coin 5 times.
o Throwing a dice 2 times.
o Selecting a number randomly uniformly from [1..n].
How to capture the following facts in the theory of probability ?
1. Outcome will always be from a specified set.
2. Likelihood of each possible outcome is non-negative.
3. We may be interested in a collection of outcomes.
12
![Page 13: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/13.jpg)
Probability Space
13
Ω
![Page 14: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/14.jpg)
Event in a Probability Space
14
AΩ
![Page 15: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/15.jpg)
Exercises
A randomized algorithm can also be viewed as a random experiment.
1. What is the sample space associated with Randomized Quick sort ?
2. What is the sample space associated with Rand-approx-medianalgorithm ?
15
![Page 16: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/16.jpg)
An Important Advice
In the following slides, we shall state well known equations (highlighted in yellow boxes) from probability theory.
• You should internalize them fully.
• We shall use them crucially in this course.
• Make sincere attempts to solve exercises that follow.
16
![Page 17: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/17.jpg)
Union of two Events
17
AB Ω
![Page 18: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/18.jpg)
Union of three Events
18
A B
C Ω
![Page 19: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/19.jpg)
Exercises
19
![Page 20: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/20.jpg)
Conditional Probability
20
![Page 21: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/21.jpg)
Exercises
• A man possesses five coins, two of which are double-headed, one is double-tailed, and two are normal. He shuts his eyes, picks a coin at random, and tosses it. What is the probability that the lower face of the coin is a head ? He opens his eyes and sees that the coin is showing heads; what it the probability that the lower face is a head ? He shuts his eyes again, and tosses the coin again. What is the probability that the lower face is a head ? He opens his eyes and sees that the coin is showing heads; what is the probability that the lower face is a head ? He discards this coin, picks another at random, and tosses it. What is the probability that it shows heads ?
21
![Page 22: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/22.jpg)
Partition of sample space and an “important Equation”
22
ΩB
![Page 23: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/23.jpg)
Exercises
23
![Page 24: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/24.jpg)
Independent Events
24
P(A ∩ B) = P(A) · P(B)
![Page 25: Lecture 2-cs648](https://reader033.vdocuments.mx/reader033/viewer/2022052508/5597df7d1a28ab5e388b4798/html5/thumbnails/25.jpg)
Exercises
25