This page looks best with JavaScript enabled

Cycle Finding Algorithms

 ·  โ˜• 1 min read · ๐Ÿ‘€... views

Floyd’s tortoise and hare

Figure 1: tortoise and hare

Figure 1: tortoise and hare

hare and tortoise both starts from point Start, at speed of \(2\) and \(1\) respectively. They’ll meet at some point in the cycle.

when they meet, hare traveled \(S_2 - S_{1}\) more points than tortoise. We have: (\(\lambda\) is the cycle length)

\[
S_{2} - S_{1} = 0 = S_{1} = x + m \pmod{\lambda}
\]

after they meet, one starts over from Start point, the other starts from Meet point, at speed of \(1\), they’ll meet again at Cycle Start point. because:

\[
x = x + m + x \pmod{\lambda}
\]

Share on