GATE / CS ARCHIVE

GATE CSE 2023 / QUESTION 13

GATE CSE 2023 Q13

Data Structures · Arrays & Linked Lists · Full GATE CSE 2023 paper

GATE 2023, Q13 1 mark · MCQ
Report issue

Arrays & Linked Lists

Question 13, GATE 2023: Given pointers to a list's head and an arbitrary node to delete, compare worst-case deletion time for singly and doubly linked lists of n nodes. A O(1),O(n); B O(log n),O(log n); C O(1),O(1); D O(n),O(1).
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Deleting an arbitrary node of a singly linked list requires locating its predecessor to reconnect the list. In the worst case the target is the tail and this takes a traversal, Θ(n); copying the next node’s value is not a universal solution for the tail. A doubly linked node directly exposes its predecessor and successor, so a constant number of links and possibly the head pointer suffice, Θ(1). Answer D.

Teaching detail. The important missing link in a singly linked node is its predecessor. Knowing the head and the target does not provide that predecessor directly, and freeing the target without redirecting its predecessor would leave a dangling link. For a doubly linked node u, set u.prev.next=u.next and u.next.prev=u.prev when those neighbors exist; handle a head or tail by changing the relevant end pointer. These are bounded operations independent of n. The worst-case claim concerns arbitrary nodes, including the tail.

Original paper, page 10 · Answer key