Floyd's tortoise & hare

a pointer algorithm that uses only two pointers, which move through the sequence at different speeds. - Cycle detection

There are 3 steps:

  • find if cycle exists
  • find position of first repetition
  • find cycle length

see rosettacode.org

Brent’s algorithm use a faster model with progressive speed.

Written on April 9, 2021, Last update on January 26, 2023
graph cycle algorithm