educative.io

Inaccurate gif on fast and slow pointers

From the diagram/gif, if the node 10 points back to node 6, aren’t the two pointers supposed to meet at node 10 given it is a singly linked list?
When slow is at node 6 and fast at node 10, slow will move to 8 and fast back to 6, then slow will move to 10 and fast will move to 10 too.


Course: Grokking Coding Interview Patterns in Python - Learn Interactively
Lesson: Fast and Slow Pointers: Introduction - Grokking Coding Interview Patterns in Python

Hello Felix,

I understand that the diagram may have caused some confusion. Let me clarify the example with a step-by-step process.

Initially, both pointers are positioned at node 2. In the first iteration, the slow pointer moves one step ahead to node 4, while the fast pointer moves two steps ahead to node 6. In the second iteration, the slow pointer moves another step ahead to node 6, while the fast pointer moves two steps ahead to node 10 where there is a loop. Finally, in the third iteration, the slow pointer moves ahead one step to node 8, while the fast pointer takes the first step to node 6 and then the second step to node 8, where both pointers meet.

I hope this explanation helps clarify the concept. If you have any further questions or concerns, please do not hesitate to reach out for assistance.

Wishing you continued success in your learning journey!
Happy Learning :smiley: