SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Randomized Algorithms
CS648

Lecture 2
‱ Randomized Algorithm for Approximate Median
‱ Elementary Probability theory
1
Randomized Monte Carlo Algorithm for
approximate median
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.

2
A simple probability exercise
‱

There is a coin which gives HEADS with probability Πand TAILS with
probability Ÿ. The coin is tossed times. What is the probability that we get at
least HEADS ?
[Stirling’s approximation for Factorial: ]

3
Probability of getting
“at least HEADS in tosses”
Probability of getting at least heads:

‱

Using Stirling’s approximation

Since , so 

Inverse exponential in .
4
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
Can you give a short proof ?

5
œ - Approximate median
A 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
Analyzing the error probability of
Rand-approx-median
n/4

Left Quarter

Elements of A arranged in
Increasing order of values

3n/4

Right Quarter

When does the algorithm err ?
To answer this question, try to characterize what
will be a bad sample S ?

7
Analyzing the error probability of
Rand-approx-median
n/4

Elements of A arranged in
Increasing order of values

Left Quarter

Median of S

3n/4

Right Quarter

Observation: Algorithm makes an error only if k/2 or more elements
sampled from the Right Quarter (or Left Quarter).

8
Analyzing the error probability of
Rand-approx-median
‱

n/4

Elements of A arranged in
Increasing order of values

3n/4

Right Quarter

Left Quarter

Pr[ An element selected randomly from A is from Right quarter] = Œ
??
Pr[ Out of k elements sampled from A, at least k/2 are from Right quarter] = ??
for

Exactly the same as the coin
tossing exercise we did !

9
Main result we discussed

‱
Theorem: The Rand-approx-median algorithm fails to report œ
-approximate median from array A[1.. ] with probability at most.
Homework: Design a randomized Monte Carlo algorithm for
computing Ï”-approximate median of array A[1.. ] with running
time O(log n loglog n) and error probability for any given
constants Ï” and .
[Do this homework sincerely without any friend’s help.]

10
Elementary probability theory
(It is so simple that you underestimate its elegance and power)

11
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
Probability Space
Definition: Probability space associated with a random experiment is an
ordered pair (Ω,P), where
‱ Ω is the set of all possible outcomes of the random experiment
‱ P : Ω R such that

‱

–

P(ω) ≄ 0 for each ωϔ Ω

Ω

Elements of Ω are called elementary events or sample points.
13
Event in a Probability Space
Definition: An event A in a probability space (Ω,P) is a subset of Ω. The
probability of event A is defined as

‱

A

Ω

For sake of compact notation, we extend P for events as described above.
14
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-median
algorithm ?

15
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
Union of two Events
Given two events A and B defined over a probability space (,P), what is
P(AUB) ?

‱

A

B

Ω

P(AUB) = P(A) + P(B)
P(A∩B)

Try to prove it by showing the following:
Each ω Ï” AUB contributes exactly P(ω) in the right hand side.
17
Union of three Events
Given three events A₁, A₂, A₃, defined over a probability space (,P), what is
P(A₁ U A₂ U A₃) ?

‱

A

B
C

Ω

P(A₁ U A₂UA₃) = P(A₁) + P(A₂) + P( A₃)
P(A₁∩A₂) P(A₂∩A₃) P(A₁∩A₃)
+ P(A₁∩A₂∩A₃)

Try to prove this equation as well by showing the following:
Each ω Ï” A₁ U A₂UA₃ contributes exactly P(ω) in the right hand side.
18
Exercises
‱

‱

For events ,
, defined over a probability space (,P), prove that P() =



)
‱

There are letters envelopes. For each letter, there is a unique envelope in
which it should be placed. A careless postman places the letters randomly
into envelopes (one letter in each envelope). What is the probability that
no letter is placed correctly (into the envelope meant for it) ?

19
Conditional Probability
Happening of some event influences the likelihood of happening of other events. This
notion is formally captured by conditional probability as follows.

‱

Probability of event A conditioned on event B, compactly represented as P[A|B],
means the following.
Given that event B has happened, what is the probability that event A has also
happened ?
You might have seen and used the following equation for conditional probability.
P[A|B] =
Can you give suitable reason to justify the validity of the above equation ?
In particular, give justification for ] in numerator and ] in denominator in this
equation.
20
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
Partition of sample space and
an “important Equation”
A set of events ,
, defined over a probability space (,P) is said to induce a
partition of if
‱ =

‱
‱

=∅ for all

B

Ω

Given an event B, how can we express P(B) in terms of a given partition ?
P(B) = )

22
Exercises
‱
‱

There are sticks each of different heights. There are vacant slots arranged
along a line and numbered from 1 to as we move from left to right. The
sticks are placed into the slots according to a uniformly random
permutation. A stick placed at th slot is said to be a dominating stick if its
height is largest among all sticks placed in slots 1 to . Find the probability
that th slot contains a dominating stick.

23
Independent Events
Two events A and B defined over a probability space (,P) are said to be
independent if happening of one of them has no influence on the probability
of the another event. Mathematically, it means that
P(A|B)= P(A) and P(B|A)=P(B)

‱

The following equation also compactly captures independence of two events.
P(A ∩ B) = P(A) · P(B)

Question: Can two independent events ever be disjoint ?

24
Exercises
‱
1.

Two fair dice are rolled. Show that the event that their sum is 7 is
independent of the score shown by the first die.

2.

Let (,P) be a probability space where = {1,2,
,p} for a given prime
number p, and each elementary event has probability 1/p. Show that if
two events A and B defined over (,P) are independent, then at least one
of A and B is either ∅ or .

25

Weitere Àhnliche Inhalte

Was ist angesagt?

Probability concepts for Data Analytics
Probability concepts for Data AnalyticsProbability concepts for Data Analytics
Probability concepts for Data AnalyticsSSaudia
 
Limits of a Function
Limits of a FunctionLimits of a Function
Limits of a FunctionJesusDel2
 
Introduction to Probability
Introduction to ProbabilityIntroduction to Probability
Introduction to ProbabilityVikas Gupta
 
Probability models & basic rules
Probability models & basic rulesProbability models & basic rules
Probability models & basic rulesamylute
 
Chapter 4 Probability Notes
Chapter 4 Probability NotesChapter 4 Probability Notes
Chapter 4 Probability Notespwheeles
 
Random variable,Discrete and Continuous
Random variable,Discrete and ContinuousRandom variable,Discrete and Continuous
Random variable,Discrete and ContinuousBharath kumar Karanam
 
Chapter 1 random variables and probability distributions
Chapter 1   random variables and probability distributionsChapter 1   random variables and probability distributions
Chapter 1 random variables and probability distributionsAntonio F. Balatar Jr.
 
Probability Review Additions
Probability Review AdditionsProbability Review Additions
Probability Review Additionsrishi.indian
 
Asymptotes and holes 97
Asymptotes and holes 97Asymptotes and holes 97
Asymptotes and holes 97swartzje
 
Sample Space and Event,Probability,The Axioms of Probability,Bayes Theorem
Sample Space and Event,Probability,The Axioms of Probability,Bayes TheoremSample Space and Event,Probability,The Axioms of Probability,Bayes Theorem
Sample Space and Event,Probability,The Axioms of Probability,Bayes TheoremBharath kumar Karanam
 
Rational Expressions
Rational ExpressionsRational Expressions
Rational ExpressionsJacob Gonzales
 
Probability Distributions for Discrete Variables
Probability Distributions for Discrete VariablesProbability Distributions for Discrete Variables
Probability Distributions for Discrete Variablesgetyourcheaton
 
Polynomials lecture
Polynomials lecturePolynomials lecture
Polynomials lectureAdnanBukhari13
 
Limits of some transcendental functions
Limits of some transcendental functionsLimits of some transcendental functions
Limits of some transcendental functionsJesusDel2
 
Chapter4
Chapter4Chapter4
Chapter4Vu Vo
 
Probability distribution
Probability distributionProbability distribution
Probability distributionRohit kumar
 

Was ist angesagt? (20)

Probability concepts for Data Analytics
Probability concepts for Data AnalyticsProbability concepts for Data Analytics
Probability concepts for Data Analytics
 
Limits of a Function
Limits of a FunctionLimits of a Function
Limits of a Function
 
Introduction to Probability
Introduction to ProbabilityIntroduction to Probability
Introduction to Probability
 
Probability And Random Variable Lecture 1
Probability And Random Variable Lecture 1Probability And Random Variable Lecture 1
Probability And Random Variable Lecture 1
 
Probability models & basic rules
Probability models & basic rulesProbability models & basic rules
Probability models & basic rules
 
Chapter 4 Probability Notes
Chapter 4 Probability NotesChapter 4 Probability Notes
Chapter 4 Probability Notes
 
Probability theory
Probability theoryProbability theory
Probability theory
 
Probability distributions
Probability distributions  Probability distributions
Probability distributions
 
Random variable,Discrete and Continuous
Random variable,Discrete and ContinuousRandom variable,Discrete and Continuous
Random variable,Discrete and Continuous
 
Chapter 1 random variables and probability distributions
Chapter 1   random variables and probability distributionsChapter 1   random variables and probability distributions
Chapter 1 random variables and probability distributions
 
Probability Review Additions
Probability Review AdditionsProbability Review Additions
Probability Review Additions
 
Asymptotes and holes 97
Asymptotes and holes 97Asymptotes and holes 97
Asymptotes and holes 97
 
Functions lect
Functions lectFunctions lect
Functions lect
 
Sample Space and Event,Probability,The Axioms of Probability,Bayes Theorem
Sample Space and Event,Probability,The Axioms of Probability,Bayes TheoremSample Space and Event,Probability,The Axioms of Probability,Bayes Theorem
Sample Space and Event,Probability,The Axioms of Probability,Bayes Theorem
 
Rational Expressions
Rational ExpressionsRational Expressions
Rational Expressions
 
Probability Distributions for Discrete Variables
Probability Distributions for Discrete VariablesProbability Distributions for Discrete Variables
Probability Distributions for Discrete Variables
 
Polynomials lecture
Polynomials lecturePolynomials lecture
Polynomials lecture
 
Limits of some transcendental functions
Limits of some transcendental functionsLimits of some transcendental functions
Limits of some transcendental functions
 
Chapter4
Chapter4Chapter4
Chapter4
 
Probability distribution
Probability distributionProbability distribution
Probability distribution
 

Ähnlich wie Lecture 2-cs648

Lecture 2-cs648
Lecture 2-cs648Lecture 2-cs648
Lecture 2-cs648Rajiv Omar
 
Basic Concept Of Probability
Basic Concept Of ProbabilityBasic Concept Of Probability
Basic Concept Of Probabilityguest45a926
 
Discrete probability
Discrete probabilityDiscrete probability
Discrete probabilityRanjan Kumar
 
Day 3.pptx
Day 3.pptxDay 3.pptx
Day 3.pptxestelaabera
 
Statistical computing 1
Statistical computing 1Statistical computing 1
Statistical computing 1Padma Metta
 
STAB52 Lecture Notes (Week 2)
STAB52 Lecture Notes (Week 2)STAB52 Lecture Notes (Week 2)
STAB52 Lecture Notes (Week 2)Danny Cao
 
Reliability-Engineering.pdf
Reliability-Engineering.pdfReliability-Engineering.pdf
Reliability-Engineering.pdfBakiyalakshmiR1
 
Probability[1]
Probability[1]Probability[1]
Probability[1]indu thakur
 
pattern recognition
pattern recognition pattern recognition
pattern recognition MohammadMoattar2
 
Mathematics for Language Technology: Introduction to Probability Theory
Mathematics for Language Technology: Introduction to Probability TheoryMathematics for Language Technology: Introduction to Probability Theory
Mathematics for Language Technology: Introduction to Probability TheoryMarina Santini
 
STOMA FULL SLIDE (probability of IISc bangalore)
STOMA FULL SLIDE (probability of IISc bangalore)STOMA FULL SLIDE (probability of IISc bangalore)
STOMA FULL SLIDE (probability of IISc bangalore)2010111
 
Chapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Chapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhChapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Chapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhbeshahashenafe20
 
Chapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Chapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhChapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Chapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhbeshahashenafe20
 
1-Probability-Conditional-Bayes.pdf
1-Probability-Conditional-Bayes.pdf1-Probability-Conditional-Bayes.pdf
1-Probability-Conditional-Bayes.pdfKrushangDilipbhaiPar
 
Machine learning mathematicals.pdf
Machine learning mathematicals.pdfMachine learning mathematicals.pdf
Machine learning mathematicals.pdfKing Khalid University
 

Ähnlich wie Lecture 2-cs648 (20)

Lecture 2-cs648
Lecture 2-cs648Lecture 2-cs648
Lecture 2-cs648
 
Basic Concept Of Probability
Basic Concept Of ProbabilityBasic Concept Of Probability
Basic Concept Of Probability
 
S244 10 Probability.ppt
S244 10 Probability.pptS244 10 Probability.ppt
S244 10 Probability.ppt
 
Discrete probability
Discrete probabilityDiscrete probability
Discrete probability
 
Basic concepts of probability
Basic concepts of probability Basic concepts of probability
Basic concepts of probability
 
Probability
ProbabilityProbability
Probability
 
Day 3.pptx
Day 3.pptxDay 3.pptx
Day 3.pptx
 
Statistical computing 1
Statistical computing 1Statistical computing 1
Statistical computing 1
 
STAB52 Lecture Notes (Week 2)
STAB52 Lecture Notes (Week 2)STAB52 Lecture Notes (Week 2)
STAB52 Lecture Notes (Week 2)
 
2ìŁŒì°š
2ìŁŒì°š2ìŁŒì°š
2ìŁŒì°š
 
Reliability-Engineering.pdf
Reliability-Engineering.pdfReliability-Engineering.pdf
Reliability-Engineering.pdf
 
Probability[1]
Probability[1]Probability[1]
Probability[1]
 
pattern recognition
pattern recognition pattern recognition
pattern recognition
 
Mathematics for Language Technology: Introduction to Probability Theory
Mathematics for Language Technology: Introduction to Probability TheoryMathematics for Language Technology: Introduction to Probability Theory
Mathematics for Language Technology: Introduction to Probability Theory
 
PTSP PPT.pdf
PTSP PPT.pdfPTSP PPT.pdf
PTSP PPT.pdf
 
STOMA FULL SLIDE (probability of IISc bangalore)
STOMA FULL SLIDE (probability of IISc bangalore)STOMA FULL SLIDE (probability of IISc bangalore)
STOMA FULL SLIDE (probability of IISc bangalore)
 
Chapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Chapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhChapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Chapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
 
Chapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Chapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhChapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Chapter Five.ppthhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
 
1-Probability-Conditional-Bayes.pdf
1-Probability-Conditional-Bayes.pdf1-Probability-Conditional-Bayes.pdf
1-Probability-Conditional-Bayes.pdf
 
Machine learning mathematicals.pdf
Machine learning mathematicals.pdfMachine learning mathematicals.pdf
Machine learning mathematicals.pdf
 

Mehr von Rajiv Omar

Lecture 6-cs345-2014
Lecture 6-cs345-2014Lecture 6-cs345-2014
Lecture 6-cs345-2014Rajiv Omar
 
Lecture 7-cs345-2014
Lecture 7-cs345-2014Lecture 7-cs345-2014
Lecture 7-cs345-2014Rajiv Omar
 
Lecture 14-2013
Lecture 14-2013Lecture 14-2013
Lecture 14-2013Rajiv Omar
 
Lecture 15
Lecture 15Lecture 15
Lecture 15Rajiv Omar
 
Lecture 16
Lecture 16Lecture 16
Lecture 16Rajiv Omar
 
Lecture 13-cs648
Lecture 13-cs648Lecture 13-cs648
Lecture 13-cs648Rajiv Omar
 
Lecture 14-cs648-2013
Lecture 14-cs648-2013Lecture 14-cs648-2013
Lecture 14-cs648-2013Rajiv Omar
 
Lecture 17-cs648
Lecture 17-cs648Lecture 17-cs648
Lecture 17-cs648Rajiv Omar
 
Lecture 18-cs648
Lecture 18-cs648Lecture 18-cs648
Lecture 18-cs648Rajiv Omar
 
Lecture 19-cs648
Lecture 19-cs648Lecture 19-cs648
Lecture 19-cs648Rajiv Omar
 
Lecture 20-cs648
Lecture 20-cs648Lecture 20-cs648
Lecture 20-cs648Rajiv Omar
 
Lecture 22-cs648
Lecture 22-cs648Lecture 22-cs648
Lecture 22-cs648Rajiv Omar
 
Lecture 3-cs648
Lecture 3-cs648Lecture 3-cs648
Lecture 3-cs648Rajiv Omar
 
Lecture 4-cs648
Lecture 4-cs648Lecture 4-cs648
Lecture 4-cs648Rajiv Omar
 
Lecture 5-cs648
Lecture 5-cs648Lecture 5-cs648
Lecture 5-cs648Rajiv Omar
 
Lecture 6-cs648
Lecture 6-cs648Lecture 6-cs648
Lecture 6-cs648Rajiv Omar
 
Lecture 7-cs648
Lecture 7-cs648Lecture 7-cs648
Lecture 7-cs648Rajiv Omar
 
Lecture 8-cs648-2013
Lecture 8-cs648-2013Lecture 8-cs648-2013
Lecture 8-cs648-2013Rajiv Omar
 
Lecture 9-cs648-2013
Lecture 9-cs648-2013Lecture 9-cs648-2013
Lecture 9-cs648-2013Rajiv Omar
 
Lecture 1-cs648
Lecture 1-cs648Lecture 1-cs648
Lecture 1-cs648Rajiv Omar
 

Mehr von Rajiv Omar (20)

Lecture 6-cs345-2014
Lecture 6-cs345-2014Lecture 6-cs345-2014
Lecture 6-cs345-2014
 
Lecture 7-cs345-2014
Lecture 7-cs345-2014Lecture 7-cs345-2014
Lecture 7-cs345-2014
 
Lecture 14-2013
Lecture 14-2013Lecture 14-2013
Lecture 14-2013
 
Lecture 15
Lecture 15Lecture 15
Lecture 15
 
Lecture 16
Lecture 16Lecture 16
Lecture 16
 
Lecture 13-cs648
Lecture 13-cs648Lecture 13-cs648
Lecture 13-cs648
 
Lecture 14-cs648-2013
Lecture 14-cs648-2013Lecture 14-cs648-2013
Lecture 14-cs648-2013
 
Lecture 17-cs648
Lecture 17-cs648Lecture 17-cs648
Lecture 17-cs648
 
Lecture 18-cs648
Lecture 18-cs648Lecture 18-cs648
Lecture 18-cs648
 
Lecture 19-cs648
Lecture 19-cs648Lecture 19-cs648
Lecture 19-cs648
 
Lecture 20-cs648
Lecture 20-cs648Lecture 20-cs648
Lecture 20-cs648
 
Lecture 22-cs648
Lecture 22-cs648Lecture 22-cs648
Lecture 22-cs648
 
Lecture 3-cs648
Lecture 3-cs648Lecture 3-cs648
Lecture 3-cs648
 
Lecture 4-cs648
Lecture 4-cs648Lecture 4-cs648
Lecture 4-cs648
 
Lecture 5-cs648
Lecture 5-cs648Lecture 5-cs648
Lecture 5-cs648
 
Lecture 6-cs648
Lecture 6-cs648Lecture 6-cs648
Lecture 6-cs648
 
Lecture 7-cs648
Lecture 7-cs648Lecture 7-cs648
Lecture 7-cs648
 
Lecture 8-cs648-2013
Lecture 8-cs648-2013Lecture 8-cs648-2013
Lecture 8-cs648-2013
 
Lecture 9-cs648-2013
Lecture 9-cs648-2013Lecture 9-cs648-2013
Lecture 9-cs648-2013
 
Lecture 1-cs648
Lecture 1-cs648Lecture 1-cs648
Lecture 1-cs648
 

KĂŒrzlich hochgeladen

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

KĂŒrzlich hochgeladen (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Lecture 2-cs648

  • 1. Randomized Algorithms CS648 Lecture 2 ‱ Randomized Algorithm for Approximate Median ‱ Elementary Probability theory 1
  • 2. Randomized Monte Carlo Algorithm for approximate median 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. 2
  • 3. A simple probability exercise ‱ There is a coin which gives HEADS with probability ÂŒ and TAILS with probability Ÿ. The coin is tossed times. What is the probability that we get at least HEADS ? [Stirling’s approximation for Factorial: ] 3
  • 4. Probability of getting “at least HEADS in tosses” Probability of getting at least heads: ‱ Using Stirling’s approximation Since , so 
 Inverse exponential in . 4
  • 5. 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 Can you give a short proof ? 5
  • 6. Âœ - Approximate median A 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
  • 7. Analyzing the error probability of Rand-approx-median n/4 Left Quarter Elements of A arranged in Increasing order of values 3n/4 Right Quarter When does the algorithm err ? To answer this question, try to characterize what will be a bad sample S ? 7
  • 8. Analyzing the error probability of Rand-approx-median n/4 Elements of A arranged in Increasing order of values Left Quarter Median of S 3n/4 Right Quarter Observation: Algorithm makes an error only if k/2 or more elements sampled from the Right Quarter (or Left Quarter). 8
  • 9. Analyzing the error probability of Rand-approx-median ‱ n/4 Elements of A arranged in Increasing order of values 3n/4 Right Quarter Left Quarter Pr[ An element selected randomly from A is from Right quarter] = ÂŒ ?? Pr[ Out of k elements sampled from A, at least k/2 are from Right quarter] = ?? for Exactly the same as the coin tossing exercise we did ! 9
  • 10. Main result we discussed ‱ Theorem: The Rand-approx-median algorithm fails to report Âœ -approximate median from array A[1.. ] with probability at most. Homework: Design a randomized Monte Carlo algorithm for computing Ï”-approximate median of array A[1.. ] with running time O(log n loglog n) and error probability for any given constants Ï” and . [Do this homework sincerely without any friend’s help.] 10
  • 11. Elementary probability theory (It is so simple that you underestimate its elegance and power) 11
  • 12. 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
  • 13. Probability Space Definition: Probability space associated with a random experiment is an ordered pair (Ω,P), where ‱ Ω is the set of all possible outcomes of the random experiment ‱ P : Ω R such that ‱ – P(ω) ≄ 0 for each ωϔ Ω Ω Elements of Ω are called elementary events or sample points. 13
  • 14. Event in a Probability Space Definition: An event A in a probability space (Ω,P) is a subset of Ω. The probability of event A is defined as ‱ A Ω For sake of compact notation, we extend P for events as described above. 14
  • 15. 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-median algorithm ? 15
  • 16. 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
  • 17. Union of two Events Given two events A and B defined over a probability space (,P), what is P(AUB) ? ‱ A B Ω P(AUB) = P(A) + P(B) P(A∩B) Try to prove it by showing the following: Each ω Ï” AUB contributes exactly P(ω) in the right hand side. 17
  • 18. Union of three Events Given three events A₁, A₂, A₃, defined over a probability space (,P), what is P(A₁ U A₂ U A₃) ? ‱ A B C Ω P(A₁ U A₂UA₃) = P(A₁) + P(A₂) + P( A₃) P(A₁∩A₂) P(A₂∩A₃) P(A₁∩A₃) + P(A₁∩A₂∩A₃) Try to prove this equation as well by showing the following: Each ω Ï” A₁ U A₂UA₃ contributes exactly P(ω) in the right hand side. 18
  • 19. Exercises ‱ ‱ For events ,
, defined over a probability space (,P), prove that P() = 
 ) ‱ There are letters envelopes. For each letter, there is a unique envelope in which it should be placed. A careless postman places the letters randomly into envelopes (one letter in each envelope). What is the probability that no letter is placed correctly (into the envelope meant for it) ? 19
  • 20. Conditional Probability Happening of some event influences the likelihood of happening of other events. This notion is formally captured by conditional probability as follows. ‱ Probability of event A conditioned on event B, compactly represented as P[A|B], means the following. Given that event B has happened, what is the probability that event A has also happened ? You might have seen and used the following equation for conditional probability. P[A|B] = Can you give suitable reason to justify the validity of the above equation ? In particular, give justification for ] in numerator and ] in denominator in this equation. 20
  • 21. 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
  • 22. Partition of sample space and an “important Equation” A set of events ,
, defined over a probability space (,P) is said to induce a partition of if ‱ = ‱ ‱ =∅ for all B Ω Given an event B, how can we express P(B) in terms of a given partition ? P(B) = ) 22
  • 23. Exercises ‱ ‱ There are sticks each of different heights. There are vacant slots arranged along a line and numbered from 1 to as we move from left to right. The sticks are placed into the slots according to a uniformly random permutation. A stick placed at th slot is said to be a dominating stick if its height is largest among all sticks placed in slots 1 to . Find the probability that th slot contains a dominating stick. 23
  • 24. Independent Events Two events A and B defined over a probability space (,P) are said to be independent if happening of one of them has no influence on the probability of the another event. Mathematically, it means that P(A|B)= P(A) and P(B|A)=P(B) ‱ The following equation also compactly captures independence of two events. P(A ∩ B) = P(A) · P(B) Question: Can two independent events ever be disjoint ? 24
  • 25. Exercises ‱ 1. Two fair dice are rolled. Show that the event that their sum is 7 is independent of the score shown by the first die. 2. Let (,P) be a probability space where = {1,2,
,p} for a given prime number p, and each elementary event has probability 1/p. Show that if two events A and B defined over (,P) are independent, then at least one of A and B is either ∅ or . 25