Final Exam, CM*C 3140, Fall 2025
Name ______________________________________
- The weight for each question is given.
- Use as much paper as you wish, but make your answers are legible.
- Please label your answers with the question number.
- Please answer each question thoughtfully and carefully.
- Please staple this page on top of your answers.
- Answer should reflect the material presented in class.
- 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 -1You may assume index computations are "correct".- if start > end
- return NOT_FOUND
- trinity = (end - start) / 3
- m1 = start + trinity
- if A[m1] == key
- return m1
- if A[m1] > key
- return NEO-SEARCH(A, key, start, m1-1)
- m2 = m1 + trinity + 1
- if A[m2] == key
- return m2
- if A[m2] > key
- return NEO-SEARCH(A, key, m1+1, m2-1)
- else
- return NEO-SEARCH(A, key, m2+1, end)
- [5 points] Trace this code A = {1, 2, 3, 4, 5, 6, 7, 8, 9}, start = 0, end = 8, key = 5
- [5 points] Describe, at a high level, how this search works.
- [3 points] Build a recurrence relation to show the performance of this search.
- [5 points] Solve the recurrence relation to find the asymptotic performance of this algorithm.
- [2 points] How does this algorithm compare to Binary Search asymptotically? Is it better?
More questions on the back
- Please investigate the following algorithm
VISIT(t, d) Input: t a node in a tree d an integer Output: The depth of the tree,- if t == null
- return 0
- t.d = d
- cost = d
- for each c ∈ t.children()
- cost = max(c, VISIT(c, d+1))
- return cost
- [5 points] Draw an arbitrary tree (T) with leaf nodes at three different depths. Use this tree to trace VISIT(T.root, 0)
- [5 points] Describe, at a high level, what this function does.
- [5 points] Argue that this routine will properly compute the depth of each node as well a the total depth of the tree.
- [5 points] Provide the performance of this algorithm. Do not use a recurrence relation. Argue that your performance is correct.
- [10 points] Describe the strengths and weaknesses of asymptotic analysis.