Cycle detection (graph theory)