Explain how to detect whether a graph contains a cycle. Cover both undirected and directed graphs, and describe what traversal state you would maintain in each case.
What to Address
How DFS works for cycle detection
Why undirected graphs need parent tracking
Why directed graphs need recursion-stack or node-state tracking
How to handle disconnected graphs
Interview Signals
Correctly distinguishes directed vs undirected logic