ProgrammingModerate

Deleting a node from the middle of a doubly linked list of length n costs what, if a pointer to the node is already known?

  1. A. O(n), because the head must be found first
  2. B. O(log n), because the list is balanced
  3. C. O(1), because the node's prev and next pointers give the neighbours directly
  4. D. O(n^2), because every node is shifted

Correct answer: C. O(1), because the node's prev and next pointers give the neighbours directly

With a known node, its neighbours are reached through prev and next. No traversal is needed.

More C Programming questions

Exams that ask this topic