WorkspaceLearning path
Level 4 · Graph Algorithms
BUILD YOUR INTUITION

DFS

Explore one branch as far as possible before returning to other frontier entries.

THE MENTAL MODEL

When 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.