Home

[This page is auto-generated; please prefer to read the article’s PDF Form.]



[Prev]   [Up]   [Next]   

Finding n

When the cycle-searching loop terminates, both R1 and R2 are at element et (= e2t). We know that et belongs to the cycle. Now, if R1 is stepped n times, it must again meet R2. So, we can iteratively step R1 till it meets R2, while counting the steps. This step count will be n.

The “Find n” part in method floyd() implements this approach.

[Prev]   [Up]   [Next]