Data Structures · Visualization

Circular Linked List: Introduction

Circular Linked List

A linked list variant where the last node's next pointer points back to the head instead of null, forming a ring. Time: Insert at end/front: O(1) with a tail pointer, O(n) without; Search/Traverse: O(n). Space: O(n) for n nodes.

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: Introduction

Circular Linked List

A linked list variant where the last node's next pointer points back to the head instead of null, forming a ring. Can be singly or doubly circular, and traversal never naturally terminates — you must track a stop condition (e.g. stop when you reach the starting node again).

How Circular Linked List: Introduction Works

  1. Create nodes the same way as a regular linked list, each holding data and a next pointer.
  2. Instead of setting the last node's next to null, point it back to the head node.
  3. Keep a reference to head (and optionally tail) to know where a traversal should stop.
  4. When traversing, start at head and stop as soon as current.next === head.

Circular Linked List: Introduction Worked Example

Input: Insert 10, 20, 30 into an empty circular linked list

  1. Insert 10: head = tail = Node(10); Node(10).next = Node(10) (points to itself).
  2. Insert 20: tail.next = Node(20); tail = Node(20); Node(20).next = head.
  3. Insert 30: tail.next = Node(30); tail = Node(30); Node(30).next = head.
  4. Traverse from head: 10 → 20 → 30 → back to 10 (stop).

Output: Ring structure: 10 → 20 → 30 → (back to 10)

📖 Introduction: this is an overview of the topic, so there's nothing to run here. Pick an operation from the side menu to see a live, step-by-step animation.
Circular Linked List: Introduction
A singly linked list whose tail points back at the head — the list becomes a ring with no null terminator.
10➜
→
20➜
→
30↺
↔ back to head 10
Active / pointers ↺ tail → head (no null)
Circular Linked List: Introduction
Press ▶ Run to watch it step by step.
Python · Circular Linked Lists in Code
class Node:
    def __init__(self, v):
        self.val = v
        self.next = None

def build_circular(values):
    head = None
    tail = None
    for v in values:                 # link tail -> head
        node = Node(v)
        if head is None:
            head = tail = node
        else:
            tail.next = node
            tail = node
    tail.next = head                 # closes the ring
    return head

head = build_circular([1, 2, 3])
# example: view on [10, 20, 30]

Circular Linked List: Introduction Time & Space Complexity

TimeInsert at end/front: O(1) with a tail pointer, O(n) without; Search/Traverse: O(n)
SpaceO(n) for n nodes

When to Use Circular Linked List: Introduction

  • Round-robin CPU scheduling
  • Multiplayer turn-based games (cycling through players)
  • Circular buffers / streaming data
  • Josephus problem simulations

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.