Lecture 9 Randomized Algorithms
Dive into the world of randomized algorithms with a focus on quicksort, quickselection, recursion, rejection sampling, biased coin simulation, and Monte Carlo algorithms. Explore concepts, examples, and applications in this fascinating field.
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.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
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.
E N D
Presentation Transcript
Quicksort Goal: Sort a list of numbers a[] = {4, 2, 8, 6, 3, 1, 7, 5} Algorithm: Pick a random pivot number (say 3) Partition the array into numbers smaller and larger than the pivot ({2, 1}, {4, 8, 6, 7, 5}) Recursively sort the two parts.
Recursion Consider the possible choices for the first pivot Let Xnbe a random variable that represents the running time of QuickSort on n numbers. ? ? ??= Pr ????? = ? ?[??|????? = ?] ?=1 1 ? ?=1 ? = ? ?? 1+ ?? + ?[?? ?] Split cost Right Part Left Part
QuickSelection Goal: Given an array of numbers Find the k-th smallest number. Example: a[] = {4, 2, 8, 6, 3, 1, 7, 5} k = 3 Output = 3
Recursion Consider the possible choices for the first pivot Let Xn be a random variable that represents the running time of QuickSelect on n numbers. ? ? ??= Pr ????? = ? ?[??|????? = ?] ?=1 1 ? ?=1 ? 1 ? ? ?? ? +1 = ? ?? 1+ ?? ? ?=?+1 Right Part Left Part Split cost
Rejection Sampling Problem: Given a random variable X, Pr[X=i] = pi want to generate a random variable Y, such that Pr[Y=i] = qi Rejection sampling: Sample X, then with probability ?? ???, keep the sample otherwise throw the sample away.
Example: Biased Coin Suppose we only have a biased coin (the coin lands on heads with probability p > ). How do we simulate a fair coin? [Von Neumann] Toss the coin twice, if the result is HT, claim Heads; if the result is TH, claim Tails; if the result is HH or TT, retry. Question: How many coin tosses do we need to do until we get the result?
Monte Carlo Algorithm Problem: Compute the area of a circle. Monte-Carlo algorithm Count = 0 FOR i = 1 to n Generate x, y from [-1,1] IF x2+y2 <= 1 THEN Count = Count + 1 RETURN 4.0*Count/n