DEV Community

Discussion on: Floyd's Tortoise and Hare Algorithm: Finding a Cycle in a Linked List

Collapse
 
fjch1997 profile image
Jingchao Feng

Can you please explain why this algorithm is correct on any graph?

Collapse
 
diogenesoftoronto profile image
Diogenesoftoronto

Think of a clock with a minute hand and an hour hand, is there a way to spin the hands without the two hands ever converging on the same number? Now add a second hand, do the hands all still converge? We can continuously do this.