Circular Linked List. Data Structures & Algorithms Prepared by: Ahsan.
Introduction. A Circular Linked List is a variation of the linked list in which the last node points back to the first node instead of pointing to NULL. This structure forms a circular chain of nodes..
Important Definitions. Node: A basic unit containing data and a pointer. Pointer (Link): Stores the address of the next node. Head: The first node of the list. Circular Linked List: A linked list where the last node points to the head node..
Theoretical Explanation. In a Circular Linked List: - Each node has data and a next pointer. - The last node does not contain NULL. - Traversal continues until we reach the head again. - It can be singly circular or doubly circular..
Types of Circular Linked List. 1. Singly Circular Linked List 2. Doubly Circular Linked List In singly circular list, each node points to next node only. In doubly circular list, nodes point to both next and previous nodes..
Pictorial Representation. Head → [10] → [20] → [30] ↑ ↓ ← ← ← ← ← ← ← ← ← ← ← ← The last node points back to the head, forming a circle..
Traversal Algorithm. Step 1: Start from head node. Step 2: Print the data of current node. Step 3: Move to the next node. Step 4: Repeat until current node becomes head again..
Pseudo Code (Traversal). if head == NULL: return temp = head do: print(temp.data) temp = temp.next while temp != head.
Example. Consider nodes with values: 5, 10, 15 Head → 5 → 10 → 15 → Head Traversal output: 5 10 15.
Solved Example. Problem: Traverse a circular linked list with nodes 1, 2, 3. Solution: Start at head (1) Print 1 → Move to 2 Print 2 → Move to 3 Print 3 → Move to head Stop traversal..
Advantages. - No NULL pointers. - Can traverse from any node. - Efficient for applications requiring continuous looping. - Useful in memory management..
Disadvantages. - Implementation is complex. - Infinite loop risk if not handled properly. - Difficult to detect the end of the list..
Applications / Real-Life Usage. - CPU scheduling (Round Robin Scheduling). - Multiplayer games. - Music playlist (loop mode). - Circular queue implementation..
Conclusion. Circular Linked List is an important data structure where nodes form a circle. It is useful in scenarios requiring continuous traversal. Proper understanding helps in efficient algorithm design..