Core idea
DFS dives deep into one branch before returning to alternatives.
It can be implemented with recursion or an explicit stack.
It is useful for connected components, cycle checks, and topological ordering.
How it works
- Start from a vertex and mark it visited.
- Move to an unvisited neighbor.
- Continue until no unvisited neighbor remains.
- Backtrack and explore the next available branch.