← Graphs & TreesDepth-First Search
Explores as far as possible along each branch before backtracking.
Step 1 of 15
Push start node "A" onto the stack.
▶Algorithm
push s onto stack
while stack not empty:
u ← pop()
if u not visited:
mark u as visited
for each neighbor v of u:
push v onto stack
// DFS complete
Legend
Active
On stack
Visited
1 / 15Speed