Shortest Paths

Advanced · 20 min read · Problem-Solving Patterns, Graphs

BFS for unweighted, Dijkstra for weighted, 0-1 BFS for in between.

This is an Advanced lesson, part of Premium. What it covers:

  • Choose by weights
  • Dijkstra: always expand the closest unfinished node
  • Dijkstra with a different cost: minimise the maximum step
  • Bellman–Ford with a limit: cheapest flights within k stops
  • 0-1 BFS: when edges cost 0 or 1
  • Practice ladder
  • Interview questions
  • Further reading

Previous: Union-Find · Next: Backtracking