Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 03 · DSA · Worked, and deeper · about 18 min to read

Play it as a journeyTutor comes with a plan

Shortest Paths, Worked (Dijkstra, Bellman-Ford, A*)

Shortest Path Traced
Shortest Path Traced · Open board

The same five-town map traced three times, once for each algorithm’s own rule for which road to check next, with the running distance written on every town.

Before you start. Graphs (BFS, DFS, Dijkstra, topological sort) showed you BFS, which finds the shortest path by counting turns, one road at a time: it assumes every road takes the same effort to drive. This lesson breaks that assumption: roads get real lengths, and three different procedures each earn their keep by handling that in a different way.

Lesson 20 of 96 in DSA

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 1956: a café terrace in Amsterdam, twenty minutes to spare
  • Rotterdam to Groningen, a five-town slice of it
  • The trick: relax every road, and keep the cheapest number
  • The catch: a road that pays you to drive it
  • Bellman-Ford: check every road, again and again
  • A*: Dijkstra with a hunch about which way to go
  • Dijkstra, traced in full
  • The pitfall that passes the sample
  • Bellman-Ford, and why V−1 passes
  • Measured at 10,000 nodes
  • A*, formalized
  • Pick the right one
  • The whole picture

Terms it explains: relaxing, Dijkstra's algorithm, Bellman-Ford, negative cycle, greedy, distance-vector routing, Admissibility, consistent.

Review DSA