Skip to main content

Detect Cycle - Floyd's Algorithm

Learn Detect Cycle - Floyd's Algorithm (Linked List, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Detecting a Cycle with Two Pointers Floyd's Cycle Detection (the "tortoise and hare") uses a slow pointer moving 1 step and a fast pointer moving 2 steps at a time. If there's a cycle, fast will eventually lap slow and they'll land on the SAME node; if there's no cycle, fast reaches null first.

More lessons in Linked List