Back to All Algorithms
Circular Linked List
Category: Data Structures | Time: O(n) Search/Insert | Space: O(n)
Visualization
Visual representation of the data structure
Enter commands to build the circular linked list.
About Circular Linked List

A Circular Linked List is a variation of a linked list in which the last node points back to the first node, creating a circle. There is no 'null' at the end. This structure is useful for applications that require continuous looping, like managing processes in a round-robin scheduler.

Code Editor
The code is for reference. Editing it won't affect the visualization.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Variable State
{
  "status": "Initializing Circular Linked List"
}
Circular Linked List: How It Works
Last updated October 28, 2026

Overview

A circular linked list is a linked list whose last node points back to the first instead of to null. There is no natural end: starting from any node and following next will eventually bring you back to where you began.

This makes it a natural fit for anything that cycles: round-robin CPU scheduling, players taking turns in a game, or a playlist on repeat. Keeping a pointer to the tail is a useful trick, because tail.next is the head, so both ends are reachable in O(1).

The default commands insert 10, 20, 30 and 40 at the end. After each insertion, the new last node's next is pointed back at 10, closing the loop. The final structure is 10 -> 20 -> 30 -> 40 -> (back to 10).

Step by step

  1. Insert into an empty list: the new node becomes the head and points to itself.
  2. Insert at the end: walk until current.next === head, set current.next = newNode and newNode.next = head.
  3. Traverse: start at the head and stop when you arrive back at the head, not when you hit null.
  4. Delete: unlink as in a singly linked list, taking care when the head itself is removed.

Complexity

CaseCostWhy
Access / searchO(n)Sequential traversal.
Insert at endO(n) or O(1)O(1) if you keep a tail pointer.
Insert at headO(1) with tail pointerInsert after the tail and update tail.next.
SpaceO(n)One pointer per node.

When to use it

  • Round-robin scheduling and turn-based games.
  • Circular buffers and repeating playlists.
  • The Josephus problem and other 'go around the circle' puzzles.

Common mistakes

  • A traversal loop that waits for null never ends — always stop when you return to the start.
  • Deleting the head requires updating the last node's next as well.
  • Single-node lists point to themselves; check that case explicitly.
Worked Example: Circular Linked List Dry Run
Generated from the same trace that drives the visualizer above, using the default input.

A dry run is the best way to check your understanding of Circular Linked List: follow each row, predict the next one, and compare. The run below takes 10 steps in total. The Line column refers to the line numbers in the code listing above.

Input
insert 10,insert 20,insert 30,insert 40
Result
status = Operations complete
StepLineWhat happens
17status = Initializing Circular Linked List
211action = insert(10)
319status = Inserted 10, head = 10
411action = insert(20)
519status = Inserted 20, head = 10
611action = insert(30)
719status = Inserted 30, head = 10
811action = insert(40)
919status = Inserted 40, head = 10
1020status = Operations complete
Frequently Asked Questions
About Circular Linked List

What is a Circular Linked List?

A Circular Linked List is a variation of a linked list in which the last node points back to the first node, creating a circle. There is no `null` at the end; instead, the `next` pointer of the last node points to the first node (the head).

What are the advantages of a Circular Linked List?

The primary advantage is that the entire list can be traversed starting from any node. It's also useful for implementing circular data structures like queues, and for applications that require continuous looping, such as round-robin scheduling in operating systems or playlists in media players.

How do you know when you've traversed the whole list?

You start at the `head` and traverse until you reach the `head` again. You need a `do-while` loop or a careful `while` loop condition to ensure the loop executes at least once if there's only one node.

What are the time complexities for operations?

  • Search: O(n).
  • Insertion at beginning/end: O(1) if a `tail` pointer is maintained, otherwise O(n).
  • Deletion: O(n) to find the element, but O(1) if a pointer to the node (and its predecessor) is known.

What is a major use case?

They are excellent for implementing round-robin algorithms. For example, in a multiplayer game, you can use a circular linked list to cycle through players for their turns.

How does insertion at the end work efficiently?

If you maintain a pointer to the `tail` node, you can insert a new node in O(1) time. The new node is inserted after the tail, and then the new node's `next` pointer is set to the head. The old tail's `next` pointer is updated to point to the new node, which becomes the new tail.

Where can I learn more?

You can find a more detailed explanation on GeeksforGeeks.