NR NR507 Week 4 Midterm Exam

26 August 2024

NR NR507 Week 4 Midterm Exam

Question 24:

The best-case scenario for an insertion sort is –

  • The elements are in reverse sorted order
  • The elements are already in sorted order (correct answer)
  • The elements are in random order
  • There is no best-case scenario

Question 25:

In the Java Class Library, the default constructor Vector creates an empty vector with an initial capacity of –

  • 0
  • 100
  • 10 (correct answer)
  • User-defined

Question 26:

In an array-based chain implementation of a Stack ADT, what is the performance of the ensureCapacity method when the array is not full? –

  • O(n)
  • O(1) (correct answer)
  • O(n log n)
  • O(n^2)

Question 27:

Stacks exhibit which type of behavior? –

  • First in, last out
  • First in, first out
  • Last in, first out (correct answer)
  • Last in, first out

Question 28:

What is the efficiency of the insertion sort method for a chain of n linked nodes? –

  • O(2n)
  • O(n)
  • O(n^2) (correct answer)
  • O(n log n)

Question 29:

The operation to retrieve the top entry of a stack without removing it is called –

  • Pop
  • Look
  • Peek (correct answer)
  • Top

Question 30:

The O(n^2) analysis of insertion sort is a(n) _______ analysis. –

  • Worst case (correct answer)
  • Best case
  • Average case
  • Unknown

Question 31:

What question should you keep in mind when debugging a recursive method? –

  • Does each base case produce a result that is correct for that case?
  • Are there enough base cases?
  • Is at least one of the cases a base case that has no recursive call?
  • All of the above (correct answer)

Question 32:

The precedence of an operator in a postfix expression –

  • Is always left-to-right
  • Is always right-to-left
  • Is implied by the order in which the operators and operands occur (correct answer)
  • Depends on the compiler implementation