A doubly linked list is a type of linked list in which each node contains a pointer to the previous node as well as the next node of the linked list. It is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains three fields: two link fields (references to the previous and next nodes) and a data field. The two node links allow traversal of the list in either direction, making it possible to traverse the list from beginning to end or from end to beginning.
Compared to a singly linked list, a doubly linked list has the following advantages:
- It can be traversed in both forward and backward directions.
- Reversing the list is easy.
- Deletion of nodes is easy.
- It has a low overhead compared to other data structures such as arrays.
- It can allocate or reallocate memory easily during its execution.
Insertion and deletion of nodes in a doubly linked list require changing more links than the same operations on a singly linked list, but the operations are simpler and potentially more efficient (for nodes other than first nodes) because there is no need to keep track of the previous node during traversal or to traverse the list to find the previous node, so that its link can be modified.
Doubly linked lists are used in various applications, such as web browsers for backward and forward navigation of web pages, constructing MRU/LRU (Most/least recently used) cache, and implementing undo and redo functionality.