Pick the fix
Why does BFS find the fewest hops but DFS may not?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A BFS visits stations in order of distance from the start
Right: all 1-hop stations come before any 2-hop station.
Layer-by-layer order guarantees the first arrival at the goal is along a shortest route when every hop costs the same.
Why not the others?
- B DFS cannot reach far stations. DFS reaches everything reachable, just not in distance order.
- C BFS uses less memory. Usually it uses more; the reason is the order of visits.