Unit 4 ยท Networks

๐Ÿ“ Shortest Path

Find the minimum-weight route between two vertices in a weighted network. Useful for minimising travel time, distance, or cost across any connected graph.

๐Ÿ”‘ Before this clicks: if any of these feel shaky, a 5-minute refresh makes this page way easier:
๐Ÿ•ธ๏ธ Graph Theory Basics

What even is this?

In a weighted graph, each edge has a number, a distance, time, or cost. The shortest path problem asks: what's the minimum total weight to get from vertex A to vertex B?

Two methods: for small graphs you can just list all paths and compare. For larger ones, use Dijkstra's algorithm, a systematic step-by-step process that always finds the right answer.

If you only do one thing Build up the shortest distance to each vertex in turn, and the lowest-total path from start to end falls out.

The 10-minute version

Low energy? Do just this and you have still won the day. Zero is the only fail.

The one move: read the first formula box and the first worked example above, then do Practice Question 1. Screenshot the win for Nat and stop there.

๐Ÿ“บ Watch it explained

Four short ways in. The ๐ŸŽฌ cards are waiting on Nat's videos, and each has a ready-to-read film script tucked underneath. ๐Ÿ–จ๏ธ Prefer printable notes? 4 styles here.

1
Method 1, Inspection (Small Graphs)

For graphs with 4 to 5 vertices, just list every possible path from start to destination, add up the weights, and take the smallest total.

A B C D 3 5 2 4 Gold = shortest path (A, B, D = 5)
1
List every path from start (A) to destination (D):
Path 1: A โ†’ B โ†’ D    Path 2: A โ†’ C โ†’ D
2
Add up the weights for each path:
A, B, D: 3 + 2 = 5
A, C, D: 5 + 4 = 9
3
Choose the minimum: shortest path is A, B, D with total distance 5
2
Method 2, Dijkstra's Algorithm

For larger networks with many possible paths, use Dijkstra's algorithm. It builds up the shortest distances from the start vertex, one confirmed vertex at a time.

Dijkstra's Algorithm, Key Rule Always "box" (finalise) the unconfirmed vertex with the smallest current tentative distance
1
Set up: Label start vertex with distance 0 (boxed โ˜…). All others start at โˆž (unknown).
2
Update neighbours: For the just-boxed vertex, calculate tentative distances to all unboxed neighbours: (current distance + edge weight). If this is smaller than their existing tentative distance, update it.
3
Box the next vertex: From all unboxed vertices, box the one with the smallest tentative distance. It's now confirmed, this is its true shortest distance.
4
Repeat steps 2 to 3 until the destination is boxed. Its confirmed distance is the answer.
3
Worked Examples
๐Ÿ—บ๏ธ
Example A ยท Inspection Method
Find the shortest path from A to D. Edges: A, B(3), A, C(5), B, D(2), C, D(4).
1

List all paths A to D

Path 1: A โ†’ B โ†’ D
Path 2: A โ†’ C โ†’ D

2

Calculate total weights

A, B, D: 3 + 2 = 5
A, C, D: 5 + 4 = 9

Shortest path: A, B, D, total distance = 5
๐Ÿงฎ
Example B ยท Dijkstra's Algorithm
Find the shortest path from A to E. Edges: A, B(2), A, C(4), B, C(1), B, D(7), C, D(3), C, E(8), D, E(2).
A B C D E 2 4 1 7 3 8 2 Gold = shortest path A, B, C, D, E = 8
1

Set up, label start vertex

A = 0 (boxed โ˜…)  |  B, C, D, E = โˆž

Dijkstra's table (โ˜… = boxed/finalised):

Step Process vertex ABCDE
Start , 0 โˆžโˆžโˆžโˆž
1 Box A (dist 0) 0 24โˆžโˆž
2 Box B (dist 2) 0 2 39โˆž
3 Box C (dist 3) 023 611
4 Box D (dist 6) 0236 8
5 Box E (dist 8) โœ“ 02368
2

Trace back the path

E(8) came from D(6+2) โ† C(3+3) โ† B(2+1) โ† A(0+2)
Shortest path: A, B, C, D, E

Shortest path: A, B, C, D, E, total distance = 2+1+3+2 = 8
Dijkstra tip: When multiple vertices tie for smallest tentative distance, you can process either one first. The final answer will be the same, but your table rows may look slightly different.
Practice, tap to reveal answers
1
A network has edges A, B(6), A, C(4), C, D(3), B, D(5). Find the shortest path from A to D using inspection.
Tap to reveal โ–พ
Path 1: A, B, D = 6 + 5 = 11
Path 2: A, C, D = 4 + 3 = 7
Shortest path: A, C, D, distance = 7
2
Using Dijkstra's on a graph: start vertex P has distance 0. It connects to Q (weight 4) and R (weight 7). After processing P, what are the tentative distances for Q and R?
Tap to reveal โ–พ
P to Q: 0 + 4 = 4
P to R: 0 + 7 = 7
Next vertex to box: Q (smallest tentative distance = 4)
3
A network has edges A, B(5), A, C(3), B, D(4), C, D(7), B, C(1). Find the shortest path from A to D.
Tap to reveal โ–พ
Possible paths A to D:
A, B, D: 5 + 4 = 9
A, C, D: 3 + 7 = 10
A, C, B, D: 3 + 1 + 4 = 8
A, B, C, D: 5 + 1 + 7 = 13
Shortest: A, C, B, D, distance = 8
4
What is the key difference between the shortest path and the minimum spanning tree for the same graph?
Tap to reveal โ–พ
The minimum spanning tree connects ALL vertices using the least total edge weight, it's a tree structure, not a route from one point to another.

The shortest path finds the minimum-weight route between two specific vertices, it doesn't need to visit all vertices, and the same edges may appear in both or neither.
5
In Dijkstra's algorithm, after boxing vertex X with confirmed distance 5, you see X connects to Y with edge weight 3, and Y's current tentative distance is 11. Do you update Y? If so, what is its new tentative distance?
Tap to reveal โ–พ
New tentative distance via X: 5 + 3 = 8
Current tentative distance of Y: 11
Since 8 < 11 โ†’ Yes, update Y to 8
Always update when the new path is shorter than the current tentative distance.
Ready to practise?
๐Ÿ—บ๏ธ
GPS Down, Escape Room
Josh is in the middle of nowhere with a dead GPS and a paper road map. Calculate the fastest routes and find the campsite before dark.
Play โ†’