Floyd's cycle-finding algorithm
ID: floyd-s-cycle-finding-algorithm
For a deterministic iteration on a finite set, move one pointer by one step and another by two steps. They eventually meet inside the repeated cycle. Restarting one pointer at the initial state and advancing both by one step locates the cycle entrance; a further traversal measures its length. The method uses constant extra space complexity and time proportional to the preperiod plus cycle length.
New to topics? Read the docs here!