What is a circular linked list (circular linked list)?
A circular linked list is a variation of a linked list in which the last node does not point to None, but instead references back to the first node (head), forming a closed loop.
That is, during traversal you can move endlessly in a circle: after the last element comes the first one again.
1. Visually
Singly linked circular list:
javascript
head → [10 | *] → [20 | *] → [30 | *] ──┐
↑──────────────────────────────┘- The last node's
nextpoints tohead. - There is no "end of the list": traversal can start from any node and will always come back around.
2. Doubly linked circular list
Here, each node has both prev and next,
and both pointers close into a loop:
javascript
↰ [10] ↔ [20] ↔ [30] ↺head.prev = tailtail.next = head
3. How it is stored
Each node has references like in a regular list, but:
- when the last element is created, its
nextpoints tohead, - (in the doubly linked variant,
head.prevalso points totail).
4. Basic operations
| Operation | Complexity | Description |
|---|---|---|
| Traversal | O(n) | You can traverse starting from any node, but you need to watch out for looping forever. |
| Insertion/deletion given a known node | O(1) | References are simply reassigned. |
| Search | O(n) | Same as in a regular list. |
5. Advantages
- You can traverse the list in a circle without checking for an "end."
- Convenient for circular structures: queues, buffers, game loops, round-robin task distribution.
- There is no "dead end" (
None); every node is connected to others.
6. Disadvantages
- You need to work carefully with the loop, otherwise the program can get stuck in endless traversal.
- Harder to control the beginning and the end.
7. Example in Python
python
class Node:
def __init__(self, data):
self.data = data
self.next = None
# creating a circular list: 10 → 20 → 30 → back to 10
n1 = Node(10)
n2 = Node(20)
n3 = Node(30)
n1.next = n2
n2.next = n3
n3.next = n1 # loop
head = n1Summary:
A circular linked list is a linked list in which the last element references back to the first one. Such a structure forms a ring, convenient for implementing circular queues, buffers, and repeating processes.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.