CSCI 385
Fall 2006
Test 1
- Use as much paper as you wish, but please label each question.
- Please write legibly.
- When you are asked to give example algorithms, use only named algorithms we have discussed in class.
- (16 points) Binary Search
- (2 points) Give a high level description of binary search.
- (4 points) Give pseudo-code for binary search.
- (2 points) Trace binary search for the input A={1,2,4,6,8,9} key = 7
- (2 points) State any conditions necessary to employ binary search.
- (2 points) State the best and worst case performance for binary search.
- (4 points) Derive the worst case performance for binary search.
- (4 points) Recursion
- State the three conditions necessary for a successful recursive
algorithm.
- (15 points) The input is a N by N matrix of numbers that is already in memory. Each individual row is increasing form left to right. Each individual column is increasing from top to bottom.
- (6 points) Give an O(N) worst case algorithm that decides if
a number X is in the matrix.
- (6 points) Give a modified versions of the binary search algorithm
that decides if a number X is in the matrix.
(Draw a picture of what you want to do, then describe it.)
- (3 points) State the worst-case performance of the algorithm
in part B.
- (10 points) Algorithm Analysis.
- (2 points) When performing algorithm analysis, you compute the performance
in terms of a variable n. How is n determined?
- (4 points) Give an example of an O(n2) algorithm.
(State the algorithm, give pseduo code, argue why the algorithm
is O(n2)).
- (4 points) Give an example of an algorithm for which the performance is based
on two different values. (State the algorithm, give the pseudo code,
state the performance).
- (5 points) Give an O(n) routine to evaluate a polynomial. Assume
that the polynomial is stored in an array, a0 at position 0,
an at position n.
- (5 points) Describe how a dynamic array can be handled such that adding items to the end of the array can be done in constant time.