This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS 234 Fall 2010 Assignment 5 Written Component Solutions 1. Recall that the average-case and worst-case runtimes of binary search are (log n ) . The average-case runtime of interpolation search is (log log n ) (assuming a relatively uniform distribution of keys) but the worst-case runtime is O ( n ) . The algorithms are exactly the same except for the formula used to determine which element to probe at each recursive call. PJ Itterp wants to have the both of best worlds by alternating which formula is used. To be more specific, when searching for a given key, the first, third, fifth, etc. recursive calls will use the binary search formula and the second, fourth, sixth, etc. recursive calls will use the interpolation search formula. (a) What is the average-case runtime of PJ Itterps algorithm (assume a relatively uniform distribution of keys)? Briefly justify your answer. [2 marks] The average-case cant be worse than twice that of interpolation search (or binary search for that matter) because half of the calls use the interpolation search formula. Also, it clearly cant be asymptotically better than that of interpolation search (the algorithm with the asymptotically better average-case runtime). Hence the average case of PJ Itterps idea is (log log n ) ....
View Full Document
This note was uploaded on 01/27/2011 for the course CS 234 taught by Professor Baranoski during the Fall '09 term at Waterloo.
- Fall '09
- Binary Search