Data Structures · Question 25 · Medium

Data Structures question 25

In a doubly linked list, you are given a pointer to a node (not the head or the tail) that must be deleted. What is the time complexity of deleting it?

  1. O(1)
  2. O(log n)
  3. O(n log n)
  4. O(n)
Answer and explanation

Answer: A. O(1)

Explanation: The node already stores pointers to both its neighbours, so you only relink prev->next and next->prev. No traversal is needed, so it takes constant time.

Previous: An undirected simple graph has 6 vertices whose degrees are 3, 3, 2, 2, 2 and… · Next: An array-based binary min-heap holds [2, 5, 3, 9, 6, 4, 8]. One deleteMin…

Practise data structures

Try a fresh set of data structures questions with an explanation after every answer, free and without signing up: Data Structures practice. Or sit a full placement mock test.

More data structures questions

More technical & programming practice

Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge