
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.
How DFS works for cycle detectionWhy undirected graphs need parent trackingWhy directed graphs need recursion-stack or node-state trackingHow to handle disconnected graphsCorrectly distinguishes directed vs undirected logicExplains the cycle condition preciselyMentions time and space complexity