1 / 8

Randomized Algorithms in Quicksort and Quickselect Explained

Learn about QuickSort and QuickSelect algorithms with random pivots, recursion, rejection sampling, and Monte Carlo simulations. Understand randomized algorithms for sorting and finding the k-th smallest number efficiently. Challenges like biased coin simulation and area computation using Monte Carlo are also explored.

lindambrown
Download Presentation

Randomized Algorithms in Quicksort and Quickselect Explained

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 9 Randomized Algorithms

  2. Quicksort • Goal: Sort a list of numbersa[] = {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.

  3. Recursion • Consider the possible choices for the first pivot • Let Xn be a random variable that represents the running time of QuickSort on n numbers. Split cost Right Part Left Part

  4. QuickSelection • Goal: Given an array of numbersFind the k-th smallest number. • Example: • a[] = {4, 2, 8, 6, 3, 1, 7, 5}k = 3 • Output = 3

  5. 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. Right Part Left Part Split cost

  6. Rejection Sampling • Problem: Given a random variable X,Pr[X=i] = piwant to generate a random variable Y, such thatPr[Y=i] = qi • Rejection sampling: Sample X, then with probability , keep the sampleotherwise throw the sample away.

  7. 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?

  8. Monte Carlo Algorithm • Problem: Compute the areaof a circle. • Monte-Carlo algorithm Count = 0 FORi = 1 to n Generate x, y from [-1,1] IF x2+y2 <= 1 THEN Count = Count + 1 RETURN 4.0*Count/n

More Related