Lesson 21/30

Tutorials DSA Mastery

Fast & Slow Pointers (Hare & Tortoise)

On this page

Fast & Slow Pointers

Also known as **Floyd's Cycle-Finding Algorithm**. This is a specific version of the Two Pointers pattern where one pointer (The Hare) moves faster than the other (The Tortoise). It is the most famous solution for Circular Linked Lists.

1. Finding the Middle of a List

If you move the 'Fast' pointer 2 steps for every 1 step the 'Slow' pointer takes, then when the Fast pointer hits the end, the Slow pointer will be at the **Exact Middle**. This is a common trick used before performing a Merge Sort on a Linked List.

2. Cycle Detection

As discussed in the Linked List module, this pattern is the primary way to detect "Loops" in a data structure using O(1) space. If the Hare ever 'laps' the Tortoise, you have a cycle.

4. Interview Mastery

Q: "Can you use this pattern on an Array?"

Architect Answer: "Yes! This is exactly how you solve the **'Find the Duplicate Number'** problem where each number represents an index for the next jump. If there is a duplicate number, jumping through the array will eventually lead you into a cycle. The Hare and Tortoise will meet, and you can then find the start of the cycle, which is the duplicate number."

Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

DSA Mastery
Course syllabus
1. Algorithmic Foundations
2. Linear Data Structures
3. Non-Linear Data Structures
4. Searching & Sorting
5. Algorithmic Patterns
6. Dynamic Programming (DP)
7. Advanced Graphs & Interview
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details