(761 Views)
Floyd’s Cycle Detection Algorithm is a pointer algorithm that makes use of only two pointers, which move through the given sequence at different speeds interval. The idea of algorithm is to move fast pointer twice as quickly as the slow pointer and the distance between the two increases by 1 at each step. If at some point both the points meet, we have a cycle in the list, else if we have reached the end of the list, no cycle is present. This algorithm is also called the “tortoise and the hare algorithm”.
Let's see a simple implementation of Floyd Cycle Detection Algorithm in Java.
1 UpvotesUpvote |
0 DownvotesDownvote |
Hello