← Back to Curriculum
FoundationsΒ·20 minΒ·Beginner
πŸ—ΊοΈ

Algorithms & Graph Search

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.

Interactive Dijkstra Visualizer

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.

Renderer
4253224362A0B∞C∞D∞E∞F∞G∞H∞
01/20

Speed

Edit Mode

Drag nodes Β· pan/zoom canvas

Templates

Graph Type

Trace Β· step 1/20

00 Initialize: dist[A] = 0, all others = ∞. Priority queue ← (0, A).

Priority Queue (min)

A:0

Distance Table

#visitABCDEFGH
0init0∞∞∞∞∞∞∞
1A0∞∞∞∞∞∞∞
2A04∞∞∞∞∞∞
3A04∞2∞∞∞∞
4D04∞2∞∞∞∞
5D04∞24∞∞∞
6B04∞24∞∞∞
7B04924∞∞∞
8B04924∞∞∞
9E04924∞∞∞
10E049248∞∞
11F049248∞∞
12F049248∞∞
13F04924811∞
14F0492481114
15C0492481114
16G0492481114
17G0492481113
18H0492481113
19done0492481113

Shortcuts: space play/pause ·←/β†’ step Β·R reset Β·V/N/E move/add/connect ·⌘Z undo Β·del delete

Before We Begin

What we are learning today

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?

Trace a computation step by step and explain why each move happensUse probability to talk about uncertainty instead of pretending outcomes are guaranteedDescribe how search algorithms compare options and settle on a good path forward

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

  • βœ“Map and navigation apps that compute low-cost routes using time, distance, or traffic
  • βœ“Network routing systems that decide how data packets should travel across the internet
  • βœ“Game and robotics pathfinding, where an agent must move through space efficiently

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.

By the end, you should be able to say:

  • Describe a graph using nodes, edges, and weights without relying on mathematical jargon
  • Explain how Dijkstra's algorithm relaxes edges and updates the best known distances
  • Connect shortest-path search to routing, robotics, scheduling, and planning problems

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

graphnodeedgeweightshortest path

What is Dijkstra's Algorithm?

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.

GraphThe map. A collection of places (nodes) and roads (edges).
WeightsThe cost. Distance, time, money β€” whatever you are trying to save.
Why AI caresBefore a robot moves, it plans. Search is the first step of action.

Algorithm Pseudocode

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 start

Do 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.

Connections to AI

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.