Workspace Depth First Search
0d
Problem-solving patterns

Depth-First Search

Follow one branch before returning for alternatives.

Recognition signal

Explore reachability, components or postorder dependencies.

Method

Mark on discovery and use an explicit or recursive stack.

Worked example

Starting at 0 on edges 0–1 and 2–3 reaches just 0 and 1.

Common mistake

A single start misses vertices outside its reachable component.