Applications, Advantages and Disadvantages of Doubly Linked List
Doubly linked list is a type of linked list in which nodes contains information and two pointers i.e. left pointer and right pointer. The left pointer in the doubly linked list points to the previous node and the right pointer points to the next node in the linked list. The first node of the doubly linked list has NULL in its left pointer and the last node of the doubly linked list has NULL in its right pointer. It is also known as a two-way linked list as there are two pointers. The benefit of this doubly linked list is that now we can navigate in both directions. Also, we can delete a node without containing the previous node’s address as every node has a left pointer that points to its previous node.
Working of a Doubly Linked List:
A Doubly linked list node contains three fields:
- Left pointer,
- Information and
- Right pointer.
The left pointer points to the node which is before the current node and the right pointer points to the node after the current node. A Doubly linked list allows backward traversing if required. All other functions are similar to linked list.
It is different from the normal linked list by allowing the bidirectional traversal which in turn reduces the time complexity of any operation.
Insertion into a doubly-linked list has three cases that are as follows:
- Inserting a new node before the head of the linked list i.e. at the beginning.
- Inserting a new node after the tail of the linked list i.e. at the end.
- Inserting a new node at a specific position.
Deletion into a doubly-linked list has three cases that are as follows:
- Deleting the first node.
- Deleting the last node.
- Deleting a specific node.
Applications of Doubly Linked List:
- Doubly linked list can be used in navigation systems where both forward and backward traversal is required.
- It can be used to implement different tree data structures.
- It can be used to implement undo/redo operations.
Real-Time Applications of Doubly Linked List:
- Doubly linked lists are used in web page navigation in both forward and backward directions.
- It can be used in games like a deck of cards.
Advantages of Doubly Linked List:
- The doubly linked list allows traversing in both forward and backward directions.
- Deletion of the nodes can be done easily.
- Reversing of linked list is easy.
- Insertion can be performed efficiently at any node.
Disadvantages of Doubly Linked List:
- In a doubly-linked list, each node has an extra pointer which requires extra space.
- Doubly linked list operations require more pointers to be handled hence, more time.
- Random access to elements is not allowed.