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 averagecase and worstcase runtimes of binary search are (log n ) . The averagecase runtime of interpolation search is (log log n ) (assuming a relatively uniform distribution of keys) but the worstcase 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 averagecase runtime of PJ Itterps algorithm (assume a relatively uniform distribution of keys)? Briefly justify your answer. [2 marks] The averagecase 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 averagecase 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
 BARANOSKI
 Binary Search

Click to edit the document details