How does Depth-First Search (DFS) help in detecting cycles in a directed graph?
Which of the alternatives best describes the DFS process?
(A) DFS detects cycles by tracking the nodes in the current recursion stack. If a node is revisited while still in the stack, it indicates a backward edge and therefore a cycle in the graph.
(B) DFS detects cycle by tracking the edges in the current graph. If an edge is created, it indicates a cycle in the graph.
(C) DFS detects cycle by tracking the nodes in the current stack. If a node is visited, it indicates a cycle in the graph.
(D) DFS does not detect cycles.
(E) None of the above.
Interesting question. But I found it too easy.
ResponderExcluir