Simply stated: “Given a list of
n
unique
values, find the
i
th
smallest.”
Common Examples
•
1
st
smallest (Minimum)
•
n
th
smallest (Maximum)
•
n/2
th
smallest (Median)
How can we approach solving such
problems?
Trivial Way: Sort the list and then return the i
th
position.
This is clearly not a good approach for
things such as minimum and maximum.
This may or may not be a good approach
for other problems such as median
finding.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
•
In the worst case, finding the minimum requires n
1 comparisons.
•
Finding the minimum can easily be done using at
worst n1 comparisons:
•
Call the first item in the list the smallest.
•
For each item remaining, compare it to the item
currently considered smallest and if it is smaller than
that item, set this new item as the smallest.
•
Do other algorithms exist?
Sure, but are they
better?
What would the runtime be of the
following recursive algorithm?
•
Split the list in half.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '11
 Staff
 Englishlanguage films

Click to edit the document details