|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Problems
Problem 2.1:
In binary search, we split the data set in half at each recursive call.
One could imagine an algorithm that split the data set up into three or
four sets at each recursive call. Provide an argument why, in Big-O
notation, binary search is as efficient as ternary search or quaternary
search.
[Solution]
Problem 2.2:
Why is linear search better implemented iteratively rather than recursively?
[Solution]
Problem 2.3:
You have an array of ints sorted in ascending order. Write a function
that recursively does a ternary search (splits the data into three sets
instead of two) on the array.
[Solution]
Problem 2.4:
Your boss tells you to write a function to search for a number in an
unbounded array (the array starts at index 0 but goes on forever). He
tells you to use the standard binary search algorithm. Explain to him
why you can't.
[Solution]
Problem 2.5:
In a last attempt to show how smart he is, your boss tells you to implement
linear search recursively as that is much more efficient than an iterative
implementation. Explain to him why he is incorrect.
[Solution]
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contact Us | Privacy Policy | Terms and Conditions | About
©2006 SparkNotes LLC, All Rights Reserved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||