How it works
Recursive or stack-based
Implement DFS with recursion or an explicit stack plus a visited set to avoid revisiting nodes.
Uses
DFS supports cycle detection, connected components, topological sort, and exhaustive path search.
When to use it
Prefer DFS when you must explore full paths or structure, not the shortest one.