Shortest paths by inspection
Find the quickest way from A to B with shortest paths in Year 12 VCE General Mathematics. A courier driving from Geelong to Torquay, a cyclist in a Bendigo charity ride or an ambulance crossing town all want the route with the smallest total distance or time, and it is often not the one with the fewest turns.
You will find shortest paths in small networks by listing the possible routes and comparing their totals. You will follow one-way streets in directed networks, adjust for closed roads, add a required stop, and convert distances to times, ready to meet Dijkstraβs algorithm, a step-by-step method for larger networks.
Theory
The shortest path between two vertices of a network is the one with the smallest total weight. This Year 12 General Mathematics guide for students in Victoria shows how to find it by inspection, listing and comparing paths, in networks and directed networks, with road closures and required stops.
In a weighted graph (a network), the length of a path is the total of the weights of the edges it uses. The weights might be distances, times or costs, so βshortestβ can also mean quickest or cheapest. The shortest path between two vertices is the path with the smallest total.
For a small network, the shortest path can be found by inspection: list the sensible paths from the start to the finish, total each one, and compare. A path with fewer edges is not always shorter, so every reasonable path must be checked. A path never needs to visit a vertex twice.
In a directed network the path must follow the arrows, so the shortest path from \(A\) to \(B\) can be different from the shortest path back from \(B\) to \(A\). If the trip must pass through a particular vertex, find the shortest path to it and the shortest path on from it, then add.
The length of a path is the total of its edge weights:
When the trip must pass through a vertex \(V\) on the way from \(S\) to \(T\):
How to find the shortest path by inspection
- Mark the start and finish. Note the edges leaving the start and arriving at the finish (in a digraph, only arrows pointing the right way).
- List the paths in an organised way, for example by the first edge used. Do not revisit a vertex.
- Total each path, one per line. Stop extending a path once its running total passes the best total found so far.
- Answer with the path written as a list of vertices and its length with units. Check every edge really exists (and points the right way).
For a network with many vertices, Dijkstraβs algorithm does the same job in a systematic table.
List every path from \(S\) to \(T\), total each one, and compare.
| \(S\text{β}B\text{β}A\text{β}C\text{β}T\) | \(:\) | \(3 + 1 + 4 + 2 = 10 \text{ km}\) |
| \(S\text{β}A\text{β}C\text{β}T\) | \(:\) | \(5 + 4 + 2 = 11 \text{ km}\) |
| \(S\text{β}B\text{β}C\text{β}T\) | \(:\) | \(3 + 7 + 2 = 12 \text{ km}\) |
| \(S\text{β}B\text{β}A\text{β}T\) | \(:\) | \(3 + 1 + 9 = 13 \text{ km}\) |
| \(S\text{β}A\text{β}T\) | \(:\) | \(5 + 9 = 14 \text{ km}\) |
| \(S\text{β}A\text{β}B\text{β}C\text{β}T\) | \(:\) | \(5 + 1 + 7 + 2 = 15 \text{ km}\) |
| \(S\text{β}B\text{β}C\text{β}A\text{β}T\) | \(:\) | \(3 + 7 + 4 + 9 = 23 \text{ km}\) |
The shortest path is \(S\text{β}B\text{β}A\text{β}C\text{β}T\), with length 10 km. It uses four edges, while the two-edge path \(S\text{β}A\text{β}T\) is 14 km.
(i) List the paths from \(S\) to \(F\), quickest first.
| \(S\text{β}K\text{β}C\text{β}M\text{β}F\) | \(:\) | \(12 + 7 + 6 + 5 = 30 \text{ min}\) |
| \(S\text{β}L\text{β}C\text{β}M\text{β}F\) | \(:\) | \(9 + 11 + 6 + 5 = 31 \text{ min}\) |
| \(S\text{β}L\text{β}F\) | \(:\) | \(9 + 22 = 31 \text{ min}\) |
| \(S\text{β}K\text{β}C\text{β}F\) | \(:\) | \(12 + 7 + 13 = 32 \text{ min}\) |
| \(S\text{β}K\text{β}M\text{β}F\) | \(:\) | \(12 + 15 + 5 = 32 \text{ min}\) |
| \(S\text{β}L\text{β}C\text{β}F\) | \(:\) | \(9 + 11 + 13 = 33 \text{ min}\) |
The other 4 paths double back across the network and each take more than \(40\) minutes. The quickest route is \(S\text{β}K\text{β}C\text{β}M\text{β}F\), taking 30 minutes.
(ii) Cross out every path that uses \(CM\). The quickest that are left are:
| \(S\text{β}L\text{β}F\) | \(:\) | \(9 + 22 = 31 \text{ min}\) |
| \(S\text{β}K\text{β}C\text{β}F\) | \(:\) | \(12 + 7 + 13 = 32 \text{ min}\) |
| \(S\text{β}K\text{β}M\text{β}F\) | \(:\) | \(12 + 15 + 5 = 32 \text{ min}\) |
With \(CM\) closed, the quickest route is \(S\text{β}L\text{β}F\), taking 31 minutes.
Follow the arrows only. List every directed path.
(i) From \(H\) the only arc goes to \(A\):
| \(H\text{β}A\text{β}C\text{β}W\) | \(:\) | \(4 + 3 + 5 = 12 \text{ min}\) |
| \(H\text{β}A\text{β}B\text{β}C\text{β}W\) | \(:\) | \(4 + 2 + 7 + 5 = 18 \text{ min}\) |
(ii) From \(W\) the only arc goes to \(D\), then \(D \to B\), then \(B \to H\):
| \(W\text{β}D\text{β}B\text{β}H\) | \(:\) | \(3 + 6 + 2 = 11 \text{ min}\) |
(i) \(H\text{β}A\text{β}C\text{β}W\), 12 minutes. (ii) \(W\text{β}D\text{β}B\text{β}H\), 11 minutes. The routes are different because the arrows only allow one direction on each street.
(ii) Split the trip: shortest \(G\) to \(P\), then shortest \(P\) to \(T\).
(i) The shortest route is \(G\text{β}B\text{β}D\text{β}T\): \(6 + 10 + 5 = 21\) km (every other path is longer).
(ii) \(G\) to \(P\):
| \(G\text{β}A\text{β}P\) | \(:\) | \(8 + 5 = 13 \text{ km}\) |
| \(G\text{β}B\text{β}P\) | \(:\) | \(6 + 9 = 15 \text{ km}\) |
| \(G\text{β}B\text{β}D\text{β}P\) | \(:\) | \(6 + 10 + 7 = 23 \text{ km}\) |
\(P\) to \(T\):
| \(P\text{β}C\text{β}T\) | \(:\) | \(4 + 6 = 10 \text{ km}\) |
| \(P\text{β}D\text{β}T\) | \(:\) | \(7 + 5 = 12 \text{ km}\) |
| \(P\text{β}A\text{β}C\text{β}T\) | \(:\) | \(5 + 12 + 6 = 23 \text{ km}\) |
| \(\text{total}\) | \(=\) | \(13 + 10\) |
| \(\) | \(=\) | \(23 \text{ km}\) |
The shortest route through \(P\) is \(G\text{β}A\text{β}P\text{β}C\text{β}T\), 23 km, which is 2 km longer than the route in (i).
Common pitfalls
Frequently asked questions
How do you find the shortest path in a network by inspection?
List the possible paths from the start to the finish, add up the edge weights along each one, and choose the path with the smallest total. Work in an organised order so no path is missed.
Is the path with the fewest edges always the shortest?
No. The shortest path has the smallest total weight. A path with more edges can be shorter if those edges have small weights.
How do you find the shortest path in a directed graph?
Do the same listing, but only follow edges in the direction of their arrows. The shortest path back can be different from the shortest path there.
How do you find the shortest path that passes through a given vertex?
Find the shortest path from the start to that vertex and the shortest path from that vertex to the finish, then add the two lengths together.
When should I use Dijkstra's algorithm instead?
Inspection works well for small networks. For bigger networks, or to find the shortest paths from one vertex to every other vertex, Dijkstra's algorithm is more reliable.