Regarding Floyd's cycle-finding algorithm

  • Thread starter Thread starter cyberfrenzy
  • Start date Start date
  • Tags Tags
    Algorithm
AI Thread Summary
Floyd's cycle-finding algorithm involves two pointers, the tortoise and the hare, moving at different speeds to detect cycles in a sequence. When starting M places apart on a cycle of size N, the distance between the two after k steps can be expressed mathematically. The tortoise moves one step per iteration, while the hare moves two steps, leading to a predictable pattern of their positions. The key is to analyze their relative positions modulo N to determine when they will coincide. A mathematical proof can be constructed to show that they will eventually meet regardless of their initial separation.
cyberfrenzy
Messages
3
Reaction score
0
Well I understand what is happening - the tortoise moving 1 step, and the hare moving 2 steps and finally coinciding at a point. But I want a mathematical proof of this - ie; when you have 2 counters moving in a cycle, one going 1 step, the other 2 steps, then they finally meet at a point.
 
Physics news on Phys.org
Suppose that they start M places apart (suitably oriented) on a cycle of size N. How many places apart are they after k steps?
 
Back
Top