Pattern Recognition Drill
Medium Graphs
The Problem
Find shortest distances from a start node in an unweighted graph.
What approach would you use?
Think about it before scrolling down.
BFS from start with distance tracking. First visit = shortest distance. O(V+E).
Dijkstra works but is overkill for unweighted graphs. BFS is simpler and equally efficient.
Common Trap
DFS does NOT give shortest paths. BFS's level-by-level exploration is what guarantees it.