Detecting a Loop in Linked List
Procedure to check if a given list has a loop using Floyd's Cycle Finding Algorithm.
Procedure :
Take two pointers : slow and fast
Move the slow pointer by 1 node each time and fast pointer by 2 nodes each time.
Perform the above step until either of the pointer become NULL or the next of fast becomes NULL.
Check if both the pointers are same. If so, the linked list has a loop. Else, it doesn't.
Contributed by Nitin Ranganath
Last updated