MediumVery High Frequency30 min
Graph DFS & Connected Components
Find islands, components, and paths using recursive and iterative DFS.
Graph DFS goes deep along one path before backtracking. Use for: cycle detection, connected components, topological sort, path existence.
Graph DFS
Graph DFS — Cycle Detection
Course Schedule (Cycle Detection)
O(V+E)Visit each node and edge once. O(V) space for color array.Step-by-step1 / 4
Graphnodes + edges
0: GRAY123
Start DFS from node 0 (GRAY)
Mark 0=GRAY. Begin exploring prerequisites.