Two Speeds
Slow moves one link while fast moves two links.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Detect Loop uses slow and fast pointers; if the fast pointer laps the slow pointer, the list contains a cycle.
Slow moves one link while fast moves two links.
In a loop, fast eventually catches slow.
If fast reaches null, the list has no cycle.
Floyd-style detection avoids storing visited nodes.