Just added: Algorithms you can run and practice
All topics / Dijkstra's Shortest Path, From Scratch

Dijkstra's Shortest Path, From Scratch

Dijkstra's algorithm taught from intuition: why BFS breaks once edges have weights, the greedy 'always expand the closest node' idea, a priority-queue implementation walked step by step across seven languages, and where it runs the real world - maps, routing, and A*.

Download EPUB
  1. Why BFS Isn't Enough for Weighted Graphs BFS finds the shortest path by counting hops, which is exactly wrong once edges carry weights - a one-hop road of weight 10 beats a two-hop route of weight 2. This phase shows that failure concretely and names the greedy fix: always expand the closest unvisited node.
  2. Dijkstra with a Priority Queue The full algorithm in code: a min-priority-queue always hands you the closest unfinalized node, edge relaxation lowers neighbors' tentative distances, and stale heap entries are skipped. Walked step by step in Python, then shown in seven languages.
  3. Where Dijkstra Runs the World Dijkstra in production: map routing and network protocols, A* as Dijkstra plus a goal-direction heuristic, and the one input that quietly breaks it - a negative edge weight, demonstrated returning the wrong answer, with Bellman-Ford as the fix.