01
You need the fewest edges β BFS, because it visits in distance layers
What you know: An unweighted graph and a shortest-path question. BFS visits everything at distance 1, then everything at distance 2, so the first arrival at a node is along a shortest path.
Rule: FIFO ⇒ min |E|
Worked example: On the 4Γ4 grid from node 0, BFS visits 0, 1, 4, 2, 5, 8, 3, 6, 9, 12, β¦ β a diagonal wavefront. DFS visits 0, 1, 2, 3, 7, 6, 5, 4, β¦ and reaches node 4 only on its eighth step.
Open this case: 4x4 Grid