Doubly linked list(also called two-way linked list) can be traversed in both directions(forward and backward).
A node in a single link list cannot be removed unless we have the pointer to its predecessor. But in doubly link list, we can delete a node even if we don't have previous node address(since, each node has left pointer pointing to previous node and can move backward).
- Each node requires an extra pointer, requiring more space.
- This insertion or deletion of a node takes a bit longer(more pointer operations)
- Inserting a new node before the head.
- Inserting a new node after the tail.
- Inserting a new node at given position.
Time Complexity: O(n), In the worst case when we need to insert node at the end of the list.
Space Complexity: O(1), For creating a temp variable.
- Deleting the first node.
- Deleting the last node.
- Deleting an intermediate node.
Time Complexity: O(n), for scanning the complete list of size n.
Space Complexity: O(1), For creating a temp variable.