Last Updated: 06 October, 2024 4 Mins
In this article, we will learn how to find the length of a circular linked list. Actually finding length means we will count the total number of nodes present in a linked list.
To count the node, we will traverse the linked list till the end node.
As we know that in a circular linked list, last node doesn't point to NULL instead it points to head; thus, we need to compare with the head pointer and traverse until the current node next is head.
For Example:
As given in the diagram, there are a total 3 nodes, so we can say that the length of a circular linked list is 3.
Output
Length of Circular Linked List is: 5
Time Complexity: O(n), here n represent the total number of nodes in a circular linked list.
Auxiliary Space: O(1)
That's all, guys. I hope this article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com