ProgrammingModerate

A singly linked list is searched for a value with a loop that stops when the value is found. For n nodes, what is the worst-case number of node visits when the value is absent?

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

Correct answer: A. n

The whole list is walked once and the search fails at the end, giving n visits.

More C Programming questions

Exams that ask this topic