ProgrammingModerate

A linear search over an array of length n finds the value only at the last position. How many comparisons does it make?

  1. A. n
  2. B. n - 1
  3. C. log n
  4. D. n + 2

Correct answer: A. n

Every element is compared once before the match at the end, giving n comparisons.

More C Programming questions

Exams that ask this topic