Fast & Slow Pointers

A pattern that uses two pointers moving at different speeds to solve complex linked list problems like cycle detection and finding the middle node.

Tortoise & Hare

Fast & Slow Pointers

Visualize pointer speed differences in action.

1🐢Slow🐇Fast234567
Ready to start
Visualization Speed800ms

Logic Tracker

O(n) Time / O(1) Space
slow = slow.next
fast = fast.next.next
if (fast == null) return slow (Middle)

Insight: Since Fast moves twice as fast as Slow, it reaches the end in exactly the time it takes Slow to reach the midpoint.

Detailed explanation about Fast & Slow Pointers.