Practice Discrete Math

Algorithms / Fast Slow Pointers

Least You Need to Know: Fast/Slow Pointers, Middle Nodes, and Cycle Entry

Fast and slow pointers turn repeated traversal into relative-motion reasoning. The same idea explains finding middle nodes, detecting linked-list cycles, and locating the entry point after a cycle is found.

The least you need to know

Key notation

slow pointer moving one step per round
fast pointer moving two steps per round
cycle entry first node on the loop reached from the head

Tiny worked example

  • Move `slow` by one node and `fast` by two nodes.
  • If `fast` hits `null`, the list ends and there is no cycle.
  • If they meet, a cycle exists.
  • Reset one pointer to the head; moving both one step per round makes them meet again at the cycle entry.

Common mistakes

How to recognize this kind of problem

Start practice