00:00

Advantages and Disadvantages of Doubly Linked List

Last updated:

A doubly linked list gives every node a prev reference in addition to next. This page looks at what that extra reference buys you and what it costs, so you can judge when a doubly linked list is the right tool.

Advantages of Doubly Linked List

  • Traversal in both directions: you can walk from the head towards the tail with next, or from the tail towards the head with prev. Printing in reverse needs no recursion and no extra stack.
  • O(1) removal of a node you already hold: the node before it is node.prev, so unlinking takes a constant number of steps. In a singly linked list the predecessor must first be found by a walk from the head.
  • O(1) insertion before a given node: a singly linked list can only insert after a node cheaply; a doubly linked list can do both.
  • O(1) work at both ends: with head and tail references, adding or removing at the front or the back is constant time. That is why java.util.LinkedList, which implements Deque, is doubly linked.
  • No fixed capacity: nodes are created only when needed, so the list never has to be resized or copied.

Disadvantages of Doubly Linked List

  • More memory per node: every node stores one more reference than in a singly linked list (typically 4 extra bytes with compressed references on a 64-bit JVM, 8 without).
  • More links to keep correct: inserting between two nodes changes four references, and deleting changes two. Forgetting one leaves the forward and backward views of the list inconsistent.
  • Slightly slower updates: the extra reference updates make each change a little more expensive, although the time complexity is the same.
  • Still no random access: reaching position k means following links; starting from the nearer end halves the walk but it remains O(n).