AlgoScope

Fast and Slow Pointers

One pointer moves twice as fast as the other. Finds middles and cycles in one pass.

Two pointers, technique, intermediate
Slow is at 2. Fast is at 3.1234567headslowfast
Slow is at 2. Fast is at 3.1234567headslowfast

Fast and Slow Pointers: Find the middle of seven

Decision, step 2 of 5

Step 1: slow moves to 2, fast jumps two to 3.

Cost

Best
O(n)
Average
O(n)
Worst
O(n)
Space
O(1)

Leads to

Topics that need this one first.

Taught by the same lesson

Fast and Slow Pointers covers these too, in the same run.