Level 4 · Graph AlgorithmsBUILD YOUR INTUITION
Shortest Path
Associate each vertex with the least cost of reaching it under the problem's allowed moves.
THE MENTAL MODELWhen should this come to mind?
Associate each vertex with the least cost of reaching it under the problem's allowed moves.
Fewest movesMinimum route lengthDistance to a target What makes it work
The grid lesson has unit-weight orthogonal moves, so BFS applies. Network Delay Time uses Dijkstra for nonnegative weighted directed edges.
When to choose something else
Reachability alone does not require optimal distances; enumerating every route may be exponentially harder.
See the pattern in action
Change the input. Follow the state. Make it yours.