← Queue / BFS

Pattern Recognition Drill

#41 — BFS shortest path (unweighted)

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.

Key Signals

Queue / BFS

BFS from start with distance tracking. First visit = shortest distance. O(V+E).

Alt: Heap / Priority Queue

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.

← #40 #42 →