Is there any algorithm to verify whether a linked list is circular or not?
Anonymous
We maintain two pointers initialized to the head of the Linked list. Name the two pointers as slow and fast. Slow pointer is advanced once at each step and the faster pointer is advanced twice at each step. If the two pointers meets i.e. points to the same node in the list at some point of time, there is a loop in the list or else if the fast pointer reaches the end of list without overlapping with the slow pointer, then the Linked list is loop free.
Check out your Company Bowl for anonymous work chats.