Skip to content
M
hscscienceMaths Std · Y12
0/100daily goal
0
0
0 due
0
L1 · 0 XP
KJ
Your weak spots
Insights load after your first practice round.
Module 6 · L6 of 12 ~30 min MS12-7 ⚡ +50 XP available

Shortest Paths — Dijkstra's Algorithm

Uber's routing system uses a variant of Dijkstra's algorithm to find the fastest path from a driver to a passenger across Sydney's road network in under 50 milliseconds. This lesson teaches you the systematic table method that makes finding shortest paths reliable — even on exam diagrams with 6+ vertices.

Today's hook — A delivery driver in Melbourne needs the fastest route from the depot to a suburb. The map shows travel times in minutes. How would you find the absolute shortest route — not just a short one?
0/5QUESTS
Worksheets

Practise this lesson

Three printable worksheets that build from foundations to mastery — or build your own from any module’s questions.

01
Recall — your gut answer first
+5 XP warm-up

A delivery driver needs the shortest route from depot (S) to destination (T). The weighted directed network has 5 intermediate stops. How would you find the shortest path — not just guess?

Before reading on — describe your strategy.

auto-saved
02
The big idea — always extend the nearest unvisited vertex
reference

Dijkstra's algorithm finds the shortest path from a source to all other vertices. It always selects the unvisited vertex with the smallest known distance — a "greedy" strategy that is provably optimal for non-negative weights.

Distance label: the current known shortest distance from the source to each vertex. Initially: source = 0, others = ∞.

Visited / Permanent: once a vertex's distance is confirmed (it is the smallest unvisited), it is marked permanent.

Update rule: when visiting vertex V, for each neighbour W: if dist(V) + weight(V→W) < dist(W), update dist(W).

Result: after all vertices are visited, the distance labels give the shortest path lengths from the source.

DIJKSTRA'S STEPS 1.Set source=0, all others=∞ 2.Select unvisited vertex with smallest label 3.Update neighbours: if shorter path found, update 4.Mark vertex as visited (permanent) 5.Repeat steps 2–4 until all visited Final labels = shortest distances from source
For the delivery driver: Dijkstra's guarantees finding the true shortest path, not just a short one.
Use a table
Keep a table with one column per vertex. Each row represents a step. Update labels as you go. This is the expected HSC method.
Greedy = always correct
Always choosing the minimum guarantees the optimal answer for networks with non-negative weights. Never second-guess Dijkstra's.
Trace back the path
Once Dijkstra's finishes, trace backwards from destination to source to find the actual shortest route, not just the distance.
03
What you will master
Know

Key facts

  • Dijkstra's finds shortest path from source
  • Initial labels: source=0, others=∞
  • Select minimum unvisited each step
Understand

Concepts

  • Why greedy strategy works here
  • Difference between distance and path
  • How to update labels correctly
Can do

Skills

  • Complete a Dijkstra's table step by step
  • Find shortest path length between two vertices
  • Trace back the actual shortest route
04
Key terms
Source vertexThe starting vertex in Dijkstra's algorithm. Its distance label is set to 0.
Distance labelThe current known shortest distance from the source to a vertex. Initially ∞ for all except the source.
Visited (permanent)A vertex whose distance label has been confirmed as the shortest — it will not be updated again.
Update ruleIf dist(current) + edge weight < dist(neighbour), replace dist(neighbour) with the smaller value.
Shortest path treeThe subgraph formed by all the optimal paths from the source — a tree rooted at the source.
TracebackWorking backwards from destination to source using the predecessor information to find the actual path.
05
Dijkstra's algorithm — the step-by-step method
core concept

Set up: Create a table with a row for each step and a column for each vertex. Initialise: source vertex = 0, all others = ∞.

Each iteration:

  1. Select the unvisited vertex with the smallest current label. Circle it (it is now permanent).
  2. For each unvisited neighbour of that vertex: calculate new distance = current vertex label + edge weight.
  3. If this new distance is less than the neighbour's current label, update the label.
  4. Move to next row in the table and repeat.

Stop: when all vertices are visited (or when the destination is made permanent).

Key rule: You only update a vertex's label if you find a strictly shorter path. If the new path is longer or equal, keep the existing label. Once a vertex is visited (permanent), never update it again.
What to write in your book
  • Set up table: source=0, others=∞.
  • Each step: select min unvisited → update neighbours → mark visited.
  • Update only if new distance < current label.
Quick check: In Dijkstra's algorithm, the source vertex is initially given a distance label of:
06
Working through a 5-vertex example — the table method
core concept

Network: vertices S, A, B, C, T. Edges: S→A(4), S→B(2), A→C(3), A→T(6), B→A(1), B→C(5), C→T(2).

Step-by-step table:

StepVertex visitedSABCT
Init0*
1S (0)42
2B (2)37
3A (3)69
4C (6)8
5T (8)

Shortest path S→T = 8. Route: trace back T←C←A←B←S, i.e. S→B→A→C→T.

What to write in your book
  • Build the table row by row. Update labels when you find shorter paths.
  • Trace back path by following which vertex provided each update.
  • Final label of destination = shortest path length.
Which does NOT describe Dijkstra's algorithm?
07
Reading the result — distances and tracing paths
core concept

Once Dijkstra's completes:

  • The final label of each vertex = shortest distance from source to that vertex.
  • To find the actual path: work backwards from destination. At each vertex, find which predecessor provided the shortest distance.
  • For vertex W with label d: look for a vertex V where label(V) + weight(V→W) = d. V was on the shortest path to W.
Example from the table: T has label 8. C→T has weight 2; C has label 6; 6+2=8 ✓ → C precedes T.
C has label 6. A→C has weight 3; A has label 3; 3+3=6 ✓ → A precedes C.
A has label 3. B→A has weight 1; B has label 2; 2+1=3 ✓ → B precedes A.
B has label 2. S→B has weight 2; S has label 0; 0+2=2 ✓ → S precedes B.
Path: S→B→A→C→T, length 8.
What to write in your book
  • Shortest distance from source = final label of destination vertex.
  • Trace path: work backwards — find vertex V where label(V) + edge = label(W).
Complete: In Dijkstra's algorithm, once a vertex is marked as visited (permanent), its distance label _______.
PROBLEM 1 · COMPLETE DIJKSTRA'S TABLE

Network: S, A, B, C. Edges: S→A(5), S→B(3), A→C(4), B→A(2), B→C(8). Find shortest distances from S to all vertices.

1
Init: S=0, A=∞, B=∞, C=∞. Visit S (smallest unvisited).
Source gets label 0; all others start at infinity
PROBLEM 2 · FIND SHORTEST PATH BETWEEN TWO VERTICES

Using the result from Problem 1 (S=0, A=5, B=3, C=9): find the shortest path from S to C and state the route.

1
Shortest distance S to C = 9 (the final label of C)
Read directly from completed table
PROBLEM 3 · INTERPRET IN CONTEXT

A delivery network has towns A, B, C, D, E with travel times (min): A→B(8), A→C(3), B→D(6), C→B(2), C→D(9), D→E(4). Find the shortest time from A to E.

1
Init: A=0, B=∞, C=∞, D=∞, E=∞. Visit A.
Source is A
09
Practice activity
+10 XP
  1. Network: S→A(6), S→B(4), A→C(3), B→A(1), B→C(7), C→T(2), A→T(8). Use Dijkstra's to find shortest S to T.
  2. At step 2 in Dijkstra's, you visit vertex B with label 4. Neighbour A has current label 6 and edge B→A has weight 1. Do you update A? Why?
  3. A student finishes Dijkstra's and says "the shortest path to T is 12." Another student traces back and finds the route S→C→T with length 12. How are these two answers related?
  4. Why must Dijkstra's algorithm NOT be used when a network has negative-weight edges?
auto-saved
10
Revisit your thinking

Dijkstra's systematic table method guarantees the shortest path — not just a short one. The "always extend the nearest unvisited" strategy is provably optimal. Did your initial strategy match this approach?

auto-saved
01
Multiple choice
+5 XP per correct

Q1. In Dijkstra's algorithm, the source vertex is initially assigned a distance label of:

Q2. At each step of Dijkstra's algorithm, you select:

Q3. Dijkstra's algorithm updates a neighbour's label when:

Q4. After Dijkstra's algorithm completes, the final label of a vertex represents:

Q5. To find the actual shortest route (not just the distance) after Dijkstra's, you should:

02
Short answer
ApplyBand 43 marks

SA 1. Network: A→B(7), A→C(2), B→D(3), C→B(4), C→D(9), D→E(1). Use Dijkstra's algorithm starting at A to find the shortest distance to E. Show the table. (3 marks)

auto-saved
AnalyseBand 52 marks

SA 2. A student is running Dijkstra's and makes vertex C permanent with label 8. Later, they find a path to C with total weight 7. What error did the student make, and what should the correct procedure be? (2 marks)

auto-saved
Answers (click to reveal)

MC 1 — A: Source = 0.

MC 2 — C: Select minimum unvisited each step.

MC 3 — B: Update when shorter path found.

MC 4 — D: Final label = shortest distance from source.

MC 5 — B: Traceback from destination.

SA 1 (3): Correct table setup [1]; correct updates [1]; final answer E=10 and route A→C→B→D→E [1].

SA 2 (2): Error identified: made permanent before checking all unvisited [1]; correct procedure stated [1].

01
Boss battle · The Route Finder
earn bronze · silver · gold

Timed questions on Dijkstra's algorithm. Gold tier requires completing the full table correctly under time pressure.

⚔ Enter the arena

Mark lesson as complete

Tick when you've finished. This completes the MS-N2 network concepts unit.