What is the time complexity of deleting an element from a doubly linked list?

What is the time complexity of deleting an element from a doubly linked list?

a) O(1)
b) O(n)
c) O(log n)
d) O(n log n)

Answer:

a) O(1)

Explanation:

In a doubly linked list, if you have a pointer to the node you want to delete, you can perform the deletion in constant time O(1) by updating the pointers of the adjacent nodes to bypass the deleted node.

This efficiency is due to the fact that a doubly linked list contains both forward and backward links, allowing immediate access to the previous and next nodes without needing to traverse the entire list.

However, finding the node to delete in the first place takes O(n) time in the worst case, as you might need to traverse the list.

Reference:

DSA (Data Structures and Algorithms) MCQ Questions and Answers

Scroll to Top