Data Structures · Visualization

Linked List: Delete

Linked List

Deleting a node removes it from the chain by skipping over it: the node right before it is re-pointed directly to the node right after it, so the deleted node is no longer reachable. Time: O(n) to find the node, O(1) to unlink once found. Space: O(1).

Big-O: Lookup O(n); insert/delete at head O(1).

Linked List: Delete

Linked List

Deleting a node removes it from the chain by skipping over it: the node right before it is re-pointed directly to the node right after it, so the deleted node is no longer reachable. If the node to delete is the head, the head pointer itself is simply moved forward.

How Delete Works

  1. If the node to delete is the head, move head to head.next and stop.
  2. Otherwise, traverse the list keeping track of the 'previous' node while looking for the target node.
  3. Once the target node is found, set previous.next to target.next, skipping over the target.
  4. The target node is now unreachable and can be discarded.

Delete Worked Example

Input: Delete value 2 from head -> 1 -> 2 -> 3 -> null

  1. Traverse: previous = 1, current = 2 (target found)
  2. previous.next = current.next (node 3)

Output: head -> 1 -> 3 -> null

Try your own input
Linked List: Introduction
A chain of nodes, each holding a value plus a pointer to the next node — unlike an array, the values are not stored side by side in memory.
12
99
37
5
71
∅
Active / pointers Result null (end) Random pointer
Linked List: Introduction
Press ▶ Run to watch it step by step.
Python · Singly Linked List in Code
def delete_value(head, val):
    if not head:
        return None
    if head.val == val:
        return head.next       # remove head
    cur = head
    while cur.next and cur.next.val != val:
        cur = cur.next
    if cur.next:
        cur.next = cur.next.next  # skip the node
    return head
# example: delete 2 on [1, 2, 3]
Input: Delete value 2 from head -> 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(n) to find the node, O(1) to unlink once found
SpaceO(1)

When to Use Delete

  • Removing a completed task from a task queue
  • Deleting a specific browser history entry
  • Removing a player from a turn-based rotation

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.