Cycle detection is also O(n)