Depth-First Search
A
B
C
D
E
F
G
H
stack · LIFO
A
take from the top
Depth-first search plunges as deep as it can from A, using a stack. A stack is last-in-first-out, so it always dives into the most recently found node — that's why DFS goes deep before wide.
step 01/20
- just discovered
- visited
- visiting now