Linked L:ist cycle || Visualization & Animation
Finds the node where a cycle begins by resetting one pointer to head after detection; O(n) time, O(1) space.
## What is it?
After detecting a cycle in a linked list using Floyd's algorithm, find the exact node where the cycle begins.
## How it works
1. **Detect** — run fast and slow pointers until they meet inside the cycle
2. **Find start** — reset one pointer to `head`, keep the other at the meeting point, move both one step at a time
3. When they meet again → that node is the cycle start
**Why it works:** The distance from `head` to the cycle start equals the distance from the meeting point to the cycle start (mathematical proof using the cycle length).
## When to use
- Finding the entry point of a cycle (LeetCode 142)
- Diagnosing pointer corruption in linked structures
## Key Points
- O(n) time, O(1) space
- Built on top of Floyd's cycle detection
- The second phase always terminates at the cycle start, not inside it
- Using a HashSet is simpler but requires O(n) space
Category: algorithms
Difficulty: intermediate
- fast-and-slow-pointers
- linked-list
Time Complexity: O(n)
Space Complexity: O(1)
View Linked L:ist cycle || Visualization