Data Structures & AlgorithmsEasyWipro · Accenture pattern

What is the time complexity of deleting the last node of a singly linked list of n nodes when only a head pointer is kept?

  1. A. O(1) – the tail is reachable directly
  2. B. O(log n)
  3. C. O(n²)
  4. D. O(n) – the second-last node must be found to update its next pointer

Correct answer: D. O(n) – the second-last node must be found to update its next pointer

Even if a tail pointer existed, removing the tail requires its predecessor, which a singly linked list can only reach by walking from the head. A doubly linked list with a tail pointer makes this O(1).

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic