Randomized_Algorithms_I_Dorr_351_Oct16-2007

# Randomized_Algorithms_I_Dorr_351_Oct16-2007 - (n/2) th...

This preview shows pages 1–8. Sign up to view the full content.

What does it mean for a value to be randomly selected? How can we make use of randomness? Monte Carlo Algorithms Don’t always give the correct answer. The runtime can be described consistently. Las Vegas Algorithms They always give the correct answers. Their runtime is not consistent.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Algorithm Select a value at random, call it p . Partition the list around p . See if it was the median (same number in each side of the partitioning). If it is, great. If it wasn’t, oh well, try again… Question #1: Does this work? Question #2: Is it a good algorithm?
Algorithm Select a value at random, call it p . Partition around p . See if it was the median (same number in each side of the partitioning). If it wasn’t, then we have still found the x th smallest value in the list (the value of x will be based on the size of the partitions). If x is “before” the median, take the right side and find the (n/2-x) th smallest. Otherwise, take the “left” side and find the

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (n/2) th smallest. Note: If this ends up being a good idea, we’d end up coding general selection. Question #1: Does this work? Question #2: Is it a good algorithm? How do we analyze the runtime of something like this? Partitioning takes n-1 comparisons. Random number generation may take some time (we'll ignore this for now). The recursion may or may not be needed, and we don’t know exactly how many values will be passed into that recursion. T(n) = n + T(???) The best case is easy, we find it on the first shot and it’s n-1 comparisons. What about worst case and average case? We will assume unique values in the list. We’ll round things and say the partitioning takes n comparisons. We will look at “worst” expected runtime. We’ll compute assuming we have to look in the larger of the two sub-lists (which is true for median finding). We won’t worry about floor/ceiling issues in this initial exploration....
View Full Document

## This note was uploaded on 01/13/2012 for the course CMSC 351 taught by Professor Staff during the Fall '11 term at University of Louisville.

### Page1 / 8

Randomized_Algorithms_I_Dorr_351_Oct16-2007 - (n/2) th...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online