Floyd’s cycle detection

Send two markers from node #0. Find out whether the path loops and which node is its entrance.

The slow marker follows one link per turn, the fast marker two. Inside a loop the fast marker eventually catches the slow one.

After they meet, return one marker to the start. Move both one link at a time. Their first shared stop is the loop entrance.

O(n) time and O(1) extra space. The markers only need their current nodes.