04 Try it yourself Interactive
The seven-edge graph from section 02, and the ten lines from section 03. Tab across to DFS and only the frontier changes. Amber nodes in the picture are marked but still waiting in the frontier; green ones have been taken out. The panel beside it always draws the next node out at the top, so the only visible difference between the two tabs is which end new nodes join. With a queue every node one edge from the start comes out before anything two edges away; with a stack the node that comes out is the one discovered most recently, so the run keeps walking away from the start until it stops finding new ground. Change the graph, change the start node, or type your own edges. Nothing moves until you press Next.