Least You Need to Know: Cycle Detection in Directed and Undirected Graphs
Abrir lección
Cycle detection depends on graph type. In undirected graphs, you must ignore the edge back to the parent. In directed graphs, the key signal is whether DFS re-enters a node that is still on the current recursion path.