Floyd's Cycle Detection Algorithm Proof In Laymen
The easiest way to understand this is really to draw it out and move your fingers on a graph, so I recommend literally pulling out a piece of paper to follow along.
Picture the part before the cycle as a line, and the cycle is a circle. So we have a straight line of arrows pointing into a circle of arrows. The length of the line is X steps, and the length of the circle is Y steps.
After X steps, the tortoise has gotten into the cycle, and the hare is further ahead, so it definitely is in the cycle too.
To understand why the tortoise and hare meet after they get into the cycle, think about the distance between the two in the circle. Assume the hare is BEHIND the tortoise--it's a circle, so while the hare is ahead, it's also fine to think of it as behind. It's at most Y steps behind in the circle, because the circle is only size Y.
At each step, the hare moves two steps, and the tortoise only moves one step, so the hare &quot;catches up&quot; one step. Eventually it will catch up to the tortoise. It catches up in the number of steps the hare started behind the tortoise, again at most Y steps.
So it does catch up, and it catches up in at most X + Y steps.