The linked list is one of the most important concepts and data structures to learn while preparing for interviews. Having a good grasp of Linked Lists can be a huge plus point in a coding interview.
There is another type of linked list that we haven’t used yet. It is known as a Circular Linked List.
Circular Linked List
Circular Linked List is a variation of a linked list where all the nodes are connected, forming a circle. This means that there is no NULL at the end. The last node, instead of pointing to NULL, points to the first node.
A singly linked list or a doubly linked list can be converted to a circular linked list.
Advantages of Circular Linked Lists
- We can traverse the entire list using any node as the starting point. It means that any node can be the starting point. We can just end the traversal when we reach the starting node again.
- Useful for the implementation of a queue. We don’t need to store two pointers that point to the front and the rear. Instead, we can just maintain a pointer to the last inserted node. By doing this. We can always obtain the front as the next of last.
- Some problems are circular and a circular data structure like a circular linked list is ideal for them.
- Circular doubly linked lists are very useful when it comes to the implementation Fibonacci Heap and many other advanced data structures.
Disadvantages of Circular Linked Lists
- Finding the end of the list is harder, as there is no NULL to mark the end of the list.
So, in this article, we have given an introduction to circular linked lists and a few of their applications. We are going to learn about its operations like insert etc in the next article.
If you want to solve more questions on Linked List, which are curated by our expert mentors at PrepBytes, visit PrepBytes Linked List.