Pattern Recognition Drill
Easy Graphs
The Problem
Traverse a graph depth-first using an explicit stack.
What approach would you use?
Think about it before scrolling down.
Push start, loop: pop, visit if unvisited, push neighbors. O(V+E).
Common Trap
Don't forget the visited set — without it, cycles cause infinite loops.