Cycle detection / fixed point [mp]
Micro pattern¶
Description¶
Detect repeated states or an exhausted dependency process to classify termination and prevent infinite traversal.
Problems¶
Fast and slow pointers¶
Advance pointers at different speeds to detect a cycle in a next-pointer structure.
- 141. Linked List Cycle (Top Easy)
- 287. Find the Duplicate Number (Top Hard)
Remember generated states¶
Stop when a generated state repeats or reaches a terminal state.
- 166. Fraction to Recurring Decimal (Top Medium)
- 202. Happy Number (Top Medium)
Topological exhaustion¶
Detect cycles when dependency processing cannot reach every required vertex.
- 207. Course Schedule (Top Hard)
- 210. Course Schedule II (Top Hard)
- 802. Find Eventual Safe States (Graph Theory)
- 1203. Sort Items by Groups Respecting Dependencies (Graph Theory)
- 1857. Largest Color Value in a Directed Graph (Graph Theory)