Data Structures · Visualization

Circular Linked List: Delete

Circular Linked List

Deleting a node from a circular linked list requires re-linking its neighbor's next pointer around it, with special handling when deleting the head, the tail, or the only remaining node. Time: O(n) to find the node (O(1) if a direct reference is already held). Space: O(1).

Big-O: Same as a singly linked list — O(1) insert/delete at the ends (with a tail pointer), O(n) search/delete by value.

Circular Linked List: Delete

Circular Linked List

Deleting a node from a circular linked list requires re-linking its neighbor's next pointer around it, with special handling when deleting the head, the tail, or the only remaining node.

How Delete Works

  1. Locate the node to delete and the node just before it (predecessor) by traversing the ring.
  2. If it's the only node, set head and tail to null.
  3. If deleting the head, move head to head.next, then point tail.next to the new head.
  4. Otherwise, point predecessor.next to the deleted node's next, skipping over it.
  5. If the deleted node was tail, update tail to the predecessor.

Delete Worked Example

Input: Delete 20 from ring 10 → 20 → 30 → (10)

  1. Traverse: predecessor = 10, target = 20
  2. predecessor.next = target.next (30)
  3. 10.next is now 30
  4. 20 is unlinked and garbage collected

Output: New ring: 10 → 30 → (back to 10)

Try your own input
Delete by ValueO(n)
Finds the node and its predecessor, then skips the node by rewiring the predecessor’s next pointer.
10➜
→
20➜
→
30↺
↔ back to head 10
Active / pointers ↺ tail → head (no null)
Delete by Value
Press ▶ Run to watch it step by step.
Python · Circular Linked Lists in Code
def delete_node(head, value):
    if head is None or head.next is head:   # 0 or 1 node
        return None if head is None or head.val == value else head
    cur = head
    prev = None
    while True:
        if cur.val == value:
            if cur is head:
                tail = head
                while tail.next is not head:
                    tail = tail.next
                tail.next = head.next       # unlink head
                return head.next
            prev.next = cur.next
            return head
        prev = cur
        cur = cur.next
        if cur is head:
            break
    return head
# example: delete 20 on [10, 20, 30]
Input: Delete 20 from ring 10 → 20 → 30 → (10)

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) if a direct reference is already held)
SpaceO(1)

When to Use Delete

  • Removing a player who leaves a round-robin game
  • Freeing a slot in a circular buffer
  • Dynamic round-robin schedulers

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.