CSCI 385

Fall 2006

Test 1

  1. (16 points) Binary Search
    1. (2 points) Give a high level description of binary search.
    2. (4 points) Give pseudo-code for binary search.
    3. (2 points) Trace binary search for the input A={1,2,4,6,8,9} key = 7
    4. (2 points) State any conditions necessary to employ binary search.
    5. (2 points) State the best and worst case performance for binary search.
    6. (4 points) Derive the worst case performance for binary search.
  2. (4 points) Recursion
    1. State the three conditions necessary for a successful recursive algorithm.
  3. (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.
    1. (6 points) Give an O(N) worst case algorithm that decides if a number X is in the matrix.
    2. (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. (3 points) State the worst-case performance of the algorithm in part B.
  4. (10 points) Algorithm Analysis.
    1. (2 points) When performing algorithm analysis, you compute the performance in terms of a variable n. How is n determined?
    2. (4 points) Give an example of an O(n2) algorithm. (State the algorithm, give pseduo code, argue why the algorithm is O(n2)).
    3. (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. (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.
  6. (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.