Data Structures · Visualization

Doubly LL: Delete

Doubly Linked List

Deleting a node in a doubly linked list is fast once you have a reference to it, because both its neighbors are directly reachable through prev and next — there is no need to search for the previous node like in a singly linked list. Time: O(1) if the node reference is known, O(n) if searching by value. Space: O(1).

Big-O: Insert/delete at either end O(1); extra memory for prev pointers.

Doubly LL: Delete

Doubly Linked List

Deleting a node in a doubly linked list is fast once you have a reference to it, because both its neighbors are directly reachable through prev and next — there is no need to search for the previous node like in a singly linked list. You simply connect the node's neighbors to each other, skipping over the deleted node.

How Delete Works

  1. Locate (or already have a reference to) the node to delete.
  2. If the node has a previous neighbor, set prev.next to the node's next.
  3. If the node has a next neighbor, set next.prev to the node's prev.
  4. Update head or tail if the deleted node was at either end.

Delete Worked Example

Input: Delete node 2 from null <- 1 <-> 2 <-> 3 -> null

  1. node2.prev (node1).next = node2.next (node3)
  2. node2.next (node3).prev = node2.prev (node1)

Output: null <- 1 <-> 3 -> null

Try your own input
Doubly LL: Introduction
Like a linked list, but every node keeps a pointer to both the previous and the next node, so you can walk it in either direction.
head
17
prev · next
30
prev · next
43
prev · next
56
prev · next
tail
69
prev · next
Active node next pointer prev pointer
Doubly LL: Introduction
Press ▶ Run to watch it step by step.
Python · Doubly Linked List in Code
def delete_node(node):
    # node is a pointer to the target
    if node.prev:
        node.prev.next = node.next
    if node.next:
        node.next.prev = node.prev
    return node.prev or node.next

# O(1) once you hold the node
# example: delete 2 on [1, 2, 3]
Input: Delete node 2 from null <- 1 <-> 2 <-> 3 -> null

Behind the Scenes Execution

Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.

Delete Time & Space Complexity

TimeO(1) if the node reference is known, O(n) if searching by value
SpaceO(1)

When to Use Delete

  • Removing an item from an LRU cache in constant time
  • Deleting a specific entry from browser history
  • Removing a node from a deque from either end

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Ready for the next step?

See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.