A Doubly Linked List is a normal Linked List but with two pointers (or references): one pointing to the next node and another pointing to the previous node in the sequence. This bidirectional navigation allows more efficient operations, especially for traversal in both directions. Doubly linked lists are particularly useful when frequent insertions and deletions are required at both ends of the list.

Core Characteristics

  • Nodes contain pointers to both the next and previous nodes, enabling bidirectional traversal
  • Does not require contiguous memory locations
  • Efficient for frequent insertions and deletions at both ends
  • Ideal for implementing complex data structures

Key Operations

  • Add() This operation adds a new node to the doubly linked list. The new node can be inserted at the head, tail, or a specific position. The previous and next pointers need to be updated to maintain the structure. If added at the head or tail, the time complexity is O(1).. Complexity: O(n) - Linear time operation

  • Delete() This operation removes a node from the doubly linked list. The node to be deleted could be anywhere in the list, and both the previous and next pointers of neighboring nodes need to be adjusted. If deleted at the head or tail, the time complexity is O(1).. Complexity: O(n) - Linear time operation

  • Get() This operation finds and returns the first node that contains the desired value. Since a doubly linked list can be traversed from both the head and the tail, searching can be done in either direction. If the node is at the head or tail, the time complexity is O(1).. Complexity: O(n) - Linear time operation

Common Applications

  • Bidirectional traversal and efficient memory management
  • Implementation of complex data structures like deques and caches
  • Efficient insertion and deletion operations at both ends
  • Used in applications requiring frequent updates to data structures
  • Ideal for implementing undo/redo functionality in applications

Heap