Coloring

Back to Cycle Detection

A DFS-based cycle detection technique that assigns colors (white/gray/black) to vertices to track their state: unvisited, in-progress, and completed. A back edge to a gray vertex indicates a cycle. Works for directed graphs. O(V + E) time.

algorithms graph-algorithms cycle-detection coloring