# HW6 - to solve this problem 2 Show that the median of ﬁve...

This preview shows page 1. Sign up to view the full content.

Fall Semester 2008 CS300 Algorithms Homework #6 (due 11/14) 1. (a) You are given n keys and an integer k such that 1 k n . Give an eﬃcient algorithm to ﬁnd any one of the k smallest keys. (For example, if k = 3, the algorithm may provide the ﬁrst-, second-, or third-smallest key. It need not know the exact rank of the key it outputs.) How many key comparisons does your algorithm do? (Hint: Don’t look for something complicated. One insight gives a short, simple algorithm.) (b) Give a lower bound, as a function of n and k , on the number of comparisons needed
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: to solve this problem. 2. Show that the median of ﬁve numbers can be found by making six comparisons. 3. In the class, we solved the Selection Problem with an algorithm that is linear-time in the worst case by dividing the array into groups of size 5. Actually, if m is the group size, any odd values of m ≥ 5 yields a linear-time complexity. But this is not true when m < 5. Deﬁne the recurrence T ( n ) of m = 3 and prove by induction that this recurrence is in Ω( n lg n ). 1...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online