Floyd’s Tortoise and Hare

Back to Cycle Detection

A cycle detection algorithm using two pointers moving at different speeds. The slow pointer advances one step at a time while the fast pointer advances two steps. If a cycle exists, they will eventually meet. O(n) time, O(1) space. Works on linked lists and sequences.

algorithms graph-algorithms cycle-detection floyds