Final Exam, CM*C 3140, Fall 2025

Final Exam, CM*C 3140, Fall 2025

Name ______________________________________


  1. Professor Neo, who's favorite number is three, proposes the following search algorithm
    NEO-SEARCH(A,key, start, end)
       Input: an ordered array from 0 to A.size-1
              key: a potential element in that array
              start: a position in the array
              end: a position in the array
       Output: the position of the key in the array or -1
    
    1. if start > end
    2. return NOT_FOUND
    3. trinity = (end - start) / 3
    4. m1 = start + trinity
    5. if A[m1] == key
    6. return m1
    7. if A[m1] > key
    8. return NEO-SEARCH(A, key, start, m1-1)
    9. m2 = m1 + trinity + 1
    10. if A[m2] == key
    11. return m2
    12. if A[m2] > key
    13. return NEO-SEARCH(A, key, m1+1, m2-1)
    14. else
    15. return NEO-SEARCH(A, key, m2+1, end)
    You may assume index computations are "correct".
    1. [5 points] Trace this code A = {1, 2, 3, 4, 5, 6, 7, 8, 9}, start = 0, end = 8, key = 5
    2. [5 points] Describe, at a high level, how this search works.
    3. [3 points] Build a recurrence relation to show the performance of this search.
    4. [5 points] Solve the recurrence relation to find the asymptotic performance of this algorithm.
    5. [2 points] How does this algorithm compare to Binary Search asymptotically? Is it better?

    
    
    
    

    More questions on the back

    
    
    
    
    
    
    
  2. Please investigate the following algorithm
    VISIT(t, d) 
       Input: t a node in a  tree
              d an integer
       Output: The depth of the tree,
    
    1. if t == null
    2. return 0
    3. t.d = d
    4. cost = d
    5. for each c ∈ t.children()
    6. cost = max(c, VISIT(c, d+1))
    7. return cost
    1. [5 points] Draw an arbitrary tree (T) with leaf nodes at three different depths. Use this tree to trace VISIT(T.root, 0)
    2. [5 points] Describe, at a high level, what this function does.
    3. [5 points] Argue that this routine will properly compute the depth of each node as well a the total depth of the tree.
    4. [5 points] Provide the performance of this algorithm. Do not use a recurrence relation. Argue that your performance is correct.

  3. [10 points] Describe the strengths and weaknesses of asymptotic analysis.