a5solutions

a5solutions - CS 234 Fall 2010 Assignment 5 Written...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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.

Page1 / 3

a5solutions - CS 234 Fall 2010 Assignment 5 Written...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online