Midterm, CM*C 3140, Fall 2025

Midterm, CM*C 3140, Fall 2025

Name ______________________________________


  1. Asymptotic Notation
    1. [6 points] What is the problem with declaring an algorithm fast because an implementation runs in less than 4 seconds?
    2. [6 points] What characteristics are positive about O(f(n))? IE why is this a good system for analyzing algorithms?
    3. [6 points] What does it mean for an algorithm to have a performance time of O(f(n))?
    4. [2 points each] Mark each as valid or invalid. Justify your answer.
      1. 3n2 + 2n + 3 is O(n2)
      2. 3n2log2n is O(n2)
      3. 3n2 + 2n + 3 is O(n5)
  2. Given the following algorithm:
    FIND-MAX(A)
       Input: An array A from 0 to A.size-1
       Output: The maximum value stored in the array.  
    1. max ← A[0]
    2. for i ← 1 to A.size-1 do
    3. if A[i] > max
    4. max = A[i]
    5. return max
    1. [6 points] Describe how this algorithm operates at a high level.
    2. [6 points] Argue that this algorithm is correct and finds the largest value in the array.
    3. [6 points] Given the asymptotic performance of this algorithm and explain how you arrived at this function.
  3. Given the following algorithm:
    EVALUATE-POLYNOMIAL(P,x)
        Input: P an array of polynomial coefficients
               x a value at which to evaluate the polynomial
        Output: the value of the polynomial at x
               P0x0 + P1x1 + ... + Pn-1xn-1 
    1. sum ← 0
    2. for i ← 0 to P.size do
    3. sum ← sum + P[i] * power(x,i)
    4. return sum
    1. [4 points] Does this algorithm evaluate the polynomial correctly? Why or why not.
    2. [4 points] Professor Disani argues that this algorithm is not O(n). Do you agree or disagree? Explain your answer.