Graph Theory37 sections · 1633 units
Open in Course

Linked List Cycle II - Walkthrough

(Example execution)

List: 320423 \to 2 \to 0 \to -4 \to 2 (cycle at node 22). The last node points back to the second node, creating a loop. Phase 11: slow and fast start at 33. After 33 steps, they meet at node 4-4 (inside the cycle). Slow traveled 33 steps, fast traveled 66 steps.

They met inside the cycle. Phase 22: slow resets to 33, fast stays at 4-4. Both move one step at a time. They meet at node 22, the cycle start. Return node 22. This is where the tail ends and the cycle begins.