Doubly Linked List
Overview
A doubly linked list is also a linear data structure and is exactly the same as the original linked list, but each node contains data and two references (pointers) - one to the next node and another to the previous node in the sequence. It's a chain with 2 directions - back and forth. That being said - traversal in a doubly linked list is bidirectional, enabling traversal in both forward and backward directions, from the head to the tail and vice versa. Having a direct reference to the previous node from each node makes backward traversal efficient, allowing easy navigation in reverse. The first node's previous reference and the last node's next reference are typically set to null or None, marking the start and end of the list, respectively. This is virtually the same as the original linked list.
Some advantages of Doubly Linked Lists are:
Efficient for both forward and backward traversal, making reverse operations more straightforward and faster.
Useful when bidirectional traversal is necessary, such as implementing undo/redo functionality.
Provide flexibility for implementing various operations, including insertions and deletions, in both directions.
In conclusion, the choice between a singly linked list and a doubly linked list depends on specific requirements and the types of operations needed. If memory efficiency and unidirectional traversal are essential, a singly linked list may be preferred. On the other hand, if bidirectional traversal and efficient backward operations are necessary, a doubly linked list would be more suitable.
Code
Code examples are present in the next section (Doubly Linked List Operations)