🗺️Algorithms & Graph Search
How computers find good routes
Take your time with this one. The interactive parts are here to help you test the idea, not rush through it.
Pause and experiment as you go.
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?
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
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 town first, gradually expanding their map until they hit the destination.
Interactive Dijkstra Visualizer
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 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.
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.