CSCI 385 Midterm Fall 2021


  1. Given the following algorithm.
    Insert(A,x)
    // A is an array and x is of the type element of that array
    
    1. i = A.size()
    2. A.push_back(x)
    3. While i > 0 and A[i-1] > x
    4. A[i] = A[i-1]
    5. i = i - 1
    6. EndWHile
    7. A[i] = x
    1. [10 points] The purpose of this function is to maintain an ordered array. Argue that this algorithm achieves this goal or given an example where this will not be the case..
    2. [10 points] Will the index i ever be out of bounds? Given an example where this can occur or argue that it can not occur.
    3. [2 points] What is the performance of this algorithm?
  2. Asymptotic Analysis
    1. [4 points] Given $O(g(n)) = \{f(n) : \exists ~ c > 0, n_0 > 0 \ni 0 \le f(n) \le cg(n) ~ \forall ~ n \ge n_0\}$
      1. What is the purpose of the constant $n_0$?
      2. What is the purpose of the constant $c$?
    2. [2 points] What are the functions f(n) and g(n) measuring?
    3. [2 points] What is n in these functions?
    4. [4 points] Describe at least two problems this measurement of performance avoids.
    5. [4 points] In CSCI130/230 you were told to "count the loops to find $O(n)$". Critique this method for finding $O(n)$
  3. Efficiency
    1. [2 points] Give the book's definition for efficiency.
    2. [4 points] Name or describe an algorithm that is not efficient. (You probably have to state both the problem being solved and give an algorithm)
  4. Data Structures
    The definition of many data structures includes performance expectations.
    1. [4 points] Give an example of this along with the performance expectations.
    2. [2 points] Why is it important that data structures are implemented to performance expectations.