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 Itterp’s algorithm (assume a relatively uniform
distribution of keys)? Briefly justify your answer. [2 marks]
The averagecase can’t 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 can’t be asymptotically better than that of interpolation search (the
algorithm with the asymptotically better averagecase runtime). Hence the average
case of PJ Itterp’s idea is
Θ(log log
n
)
.
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.
 Fall '09
 BARANOSKI
 Binary Search, Probability theory, Big O notation, hash function, Search algorithms, PJ Itterp

Click to edit the document details