Level 4 · Graph AlgorithmsBUILD YOUR INTUITION
DFS
Explore one branch as far as possible before returning to other frontier entries.
THE MENTAL MODELWhen should this come to mind?
Explore one branch as far as possible before returning to other frontier entries.
Connected componentsFlood fillPathsSubtree work What makes it work
Mark a graph vertex before scheduling it again; trees do not require the same visited bookkeeping.
When to choose something else
For shortest paths in an unweighted graph, use BFS.
See the pattern in action
Change the input. Follow the state. Make it yours.