Pattern 03 of 08 · fast-slow-pointers
Fast & Slow Pointers
Traverse linear structures (linked lists, sequence graphs) at two distinct speeds to detect cycles and identify midpoint boundaries.
- Builds on
- Two Pointers
- Unlocks
- The end of this branch.
See the invariant
Step through itPattern InvariantFast & Slow Pointers
Floyd's Cycle Finding Algorithm (Tortoise & Hare)
Step 1 of 5
Slow/Fast
A
Node 0 B
Node 1 C
Node 2 (Cycle Start)D
Node 3 E
Node 4 F
Node 5 Initial state: Both Slow (the tortoise) and Fast (the hare) start at head Node 0 (A).
Speed: