ProgrammingModerate

A linked list of length n is reversed in place with a loop. How much extra memory is used?

  1. A. O(n), a new node for each element
  2. B. O(n log n), for a sorting buffer
  3. C. O(n^2), for a copy of each suffix
  4. D. O(1), only a few pointer variables

Correct answer: D. O(1), only a few pointer variables

The three-pointer loop reuses the nodes, so only constant extra space is needed.

More C Programming questions

Exams that ask this topic