Randomized Algorithms for Approximate Median with Elementary Probability

Slide Note
Embed
Share

This content covers a lecture on a randomized algorithm for finding an approximate median element using elementary probability theory. It discusses the importance of insight and basic probability in designing and analyzing such algorithms. The lecture presents a simple probability exercise involving coin tosses and Stirling's approximation for factorials. Additionally, it introduces the concept of approximate median, compares deterministic and randomized algorithms, and provides a randomized algorithm (Rand-Approx-Median) with its error probability analysis.


Uploaded on Oct 09, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  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 ?/2 HEADS ? [Stirling s approximation for Factorial: ?! ??)?] 2??( 3

  4. Probability of getting at least ?/2 HEADSin ? tosses Probability of getting at least ?/2 heads: ? ??[? HEADS appear in ? tosses] = ?=?/2 ? ? ? 14)? ( 34)? ? = ?=?/2 ( ? ? 14)? ( 34)? ? ?/2 ?=?/2 ? ?/2 ( ? ?/2 ( 4?/2 ( =( ( ( ? 34)? ?=?/2 13)? ( = Using Stirling s approximation ? ?/2 34)? ( 13)?/2 3 124?/2 2 4)? ( 3)?/2 3 1 4)5/2 3 12 , so Since ( 34)?/2 12)?/5 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 3n/4 Elements of A arranged in Increasing order of values Right Quarter Left 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 Median of S n/4 3n/4 Elements of A arranged in Increasing order of values Right Quarter Left 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 3n/4 Elements of A arranged in Increasing order of values 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] = ?? ( = ( = ? 2 tossing exercise we did ! 12)?/5 12)2 log ? for ? = 10log? Exactly the same as the coin 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 2 ? 2. 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 P( ) = 1 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 P( ) 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 ?1, , ??defined over a probability space (?,P), prove that P( ?=1 ??) = ?P(??) ?<?P(?? ??) + ?<?<?P(?? ?? ??) ( 1)?+1P(?1 ?2 ??) ? 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 ?1, ,??defined over a probability space (?,P) is said to induce a partition of ? if ?=1 ?? = ? ?? ??= for all? ? ? B Given an event B, how can we express P(B) in terms of a given partition ? P(B) = ?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 ? 1. 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. 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 ?. 2. 25

Related


More Related Content