How computers find good routes
See how a search algorithm compares routes, updates costs, and reliably finds a strong path through a network of choices.
Edit the graph, pick a start and target, then step through the algorithm. Toggle Wide to expand beyond the page margins and fit everything on one screen. Switch between SVG, Canvas, and 3D renderers.
Speed
Edit Mode
Drag nodes Β· pan/zoom canvas
Templates
Graph Type
00 Initialize: dist[A] = 0, all others = β. Priority queue β (0, A).
| # | visit | A | B | C | D | E | F | G | H |
|---|---|---|---|---|---|---|---|---|---|
| 0 | init | 0 | β | β | β | β | β | β | β |
| 1 | A | 0 | β | β | β | β | β | β | β |
| 2 | A | 0 | 4 | β | β | β | β | β | β |
| 3 | A | 0 | 4 | β | 2 | β | β | β | β |
| 4 | D | 0 | 4 | β | 2 | β | β | β | β |
| 5 | D | 0 | 4 | β | 2 | 4 | β | β | β |
| 6 | B | 0 | 4 | β | 2 | 4 | β | β | β |
| 7 | B | 0 | 4 | 9 | 2 | 4 | β | β | β |
| 8 | B | 0 | 4 | 9 | 2 | 4 | β | β | β |
| 9 | E | 0 | 4 | 9 | 2 | 4 | β | β | β |
| 10 | E | 0 | 4 | 9 | 2 | 4 | 8 | β | β |
| 11 | F | 0 | 4 | 9 | 2 | 4 | 8 | β | β |
| 12 | F | 0 | 4 | 9 | 2 | 4 | 8 | β | β |
| 13 | F | 0 | 4 | 9 | 2 | 4 | 8 | 11 | β |
| 14 | F | 0 | 4 | 9 | 2 | 4 | 8 | 11 | 14 |
| 15 | C | 0 | 4 | 9 | 2 | 4 | 8 | 11 | 14 |
| 16 | G | 0 | 4 | 9 | 2 | 4 | 8 | 11 | 14 |
| 17 | G | 0 | 4 | 9 | 2 | 4 | 8 | 11 | 13 |
| 18 | H | 0 | 4 | 9 | 2 | 4 | 8 | 11 | 13 |
| 19 | done | 0 | 4 | 9 | 2 | 4 | 8 | 11 | 13 |
Shortcuts: space play/pause Β·β/β step Β·R reset Β·V/N/E move/add/connect Β·βZ undo Β·del delete
Before We Begin
Search is the hidden engine behind routing, planning, scheduling, and many game-like problems. Dijkstra's algorithm offers a clean first example because it keeps a running record of the cheapest known path to every location and improves those records until the best route is confirmed.
How this lesson fits
This module builds the mental model underneath everything else in the curriculum. We start with explicit rules, then add uncertainty, then explore search, so students can see AI as a chain of concrete decisions rather than a pile of mysterious buzzwords.
The big question
How can a machine move from rigid step-by-step instructions to making sensible choices in a messy, uncertain world?
Why You Should Care
Before an AI system can act intelligently, it often has to evaluate many possible next moves. Search algorithms teach students how machines compare alternatives systematically rather than by intuition.
Where this is used today
Think of it like this
Imagine walking through a dim maze with a notebook. Every time you reach a junction, you write down how much it cost to get there. Instead of wandering randomly, you always continue from the cheapest unfinished option on your list. Order, not luck, is what gets you out.
Easy mistake to make
In graph search, 'shortest' does not have to mean the smallest physical distance. It means the lowest total cost according to whatever weights the system cares about, such as time, fuel, or risk.
Think about this first
When a navigation app avoids the route that looks physically shortest, what hidden costs might it be optimizing instead? Name as many as you can.
Words we will keep using
Dijkstra's algorithm answers a simple question: βWhat is the fastest way to get there?β It works like a cautious traveler who always explores the closest unfinished town first, keeping a running record of the cheapest known path to every place and improving those records until the best route is confirmed.
function dijkstra(graph, start):
dist[start] = 0; dist[all others] = β
pq = priority queue with (0, start)
while pq not empty:
(d, u) = pq.pop_min()
for each neighbor v of u with edge weight w:
if dist[u] + w < dist[v]:
dist[v] = dist[u] + w
pq.push((dist[v], v))
return dist // shortest distances from startDo not worry too much about the formula yet. The big idea is that a smart data structure lets the algorithm stay efficient even on larger graphs.
This idea appears everywhere in AI: robot navigation, game search, network routing, and even recommendation or knowledge systems. Once students understand shortest-path search, they have one of the core building blocks of intelligent planning.