Objective
Explore a graph with breadth-first and depth-first search and see how the frontier expands in rings versus plunging down one branch at a time.
The idea
BFS visits everything one step away before anything two steps away; DFS burrows down one path to the end. Watch the difference on the same graph.
Try this
- 1Run BFS and count the rings around the start node.
- 2Run DFS and trace the single long path it follows.
- 3Change the start node and see both shapes change.
- 4Use BFS to find the shortest hop-count path.
Watch for
- BFS expands level by level - shortest hop counts.
- DFS follows one branch all the way before backtracking.
- The queue vs the stack decides the exploration order.
- Both visit every reachable node; the order is what differs.