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 also

Written on April 9, 2021, Last update on September 16, 2024
graph cycle algorithm