Shortest Path
Every question with a fully worked solution.
- Shortest Path - Video - Shortest Path Watch
Theory
The shortest path between two vertices of a weighted network is the route with the smallest total distance, time or cost. This Year 11 Mathematics Standard page shows how to find it by inspection and by labelling each vertex with its shortest distance from the start, from a diagram, a list or a table, and how to deal with closed roads and routes that are shorter but slower.
In a weighted network, the length of a path is the total of the weights on its edges. The shortest path between two vertices is the path with the smallest total weight. The weights may be distances, travel times or costs (such as tolls), so the shortest path can also be the quickest or the cheapest route.
The shortest path is not always the one with the fewest edges. Three short roads can add to less than one long road.
There are two ways to find it:
- By inspection: list the possible routes, add the weights along each one and compare the totals. This suits small networks.
- By labelling the vertices: work outwards from the start, labelling each vertex with its shortest distance from the start. A vertex's label is the smallest of (the label of a vertex already labelled + the weight of the edge joining them). The label on the finishing vertex is the length of the shortest path. This suits larger networks and networks given as a list or a table.
Real problems add a twist: a road may be closed (remove that edge and label again), or the shortest distance may not be the quickest once speeds are taken into account.
Labelling a vertex \(D\) that is joined to labelled vertices \(B\) (label 5, edge 9) and \(C\) (label 7, edge 6):
\(\min(\ldots)\) means “the smallest of”. To compare a shortest distance with a quickest time:
By inspection
- List the routes from the start to the finish that do not pass through a vertex twice.
- Add the weights along each route.
- Compare the totals and write \(\therefore\) the shortest path has length …
By labelling the vertices
- Label the start 0. The vertex joined to it by the shortest edge is labelled with that edge's weight.
- Work outwards. For each new vertex, look at every edge into it from a vertex already labelled. Its label is the smallest of (that label + edge weight), for example \(C=\min(8,\,5+2)=7\).
- Carry on until the finishing vertex is labelled. Its label is the length of the shortest path.
- Trace back from the finish, each time along the edge that gave the label, to write the path. Check by adding its weights.
Practical problems
- From a list or table: read off each direct road first. A dash in a table means there is no direct road.
- Road closed: remove that edge and label the network again.
- Quickest route: find the time for each route using time \(=\) distance \(\div\) speed, then compare.
Compare the lengths of the possible routes:
| \(A\text{-}C\text{-}B\text{-}E\) | \(=\) | \(3+4+6=13\) |
| \(A\text{-}B\text{-}E\) | \(=\) | \(8+6=14\) |
| \(A\text{-}C\text{-}D\text{-}E\) | \(=\) | \(3+9+2=14\) |
| \(A\text{-}B\text{-}C\text{-}D\text{-}E\) | \(=\) | \(8+4+9+2=23\) |
\(\therefore\) the shortest path is \(A\)-\(C\)-\(B\)-\(E\), with length \(\mathbf{13}\) km. It has three edges but is shorter than the two-edge route \(A\)-\(B\)-\(E\).
| \(P\) | \(Q\) | \(R\) | \(S\) | \(T\) | \(U\) | |
|---|---|---|---|---|---|---|
| \(P\) | – | 5 | 9 | – | – | – |
| \(Q\) | 5 | – | 3 | 8 | – | – |
| \(R\) | 9 | 3 | – | 4 | 10 | – |
| \(S\) | – | 8 | 4 | – | 2 | 9 |
| \(T\) | – | – | 10 | 2 | – | 5 |
| \(U\) | – | – | – | 9 | 5 | – |
Read the direct roads from the table, then label each town with its shortest distance from \(P\):
| \(Q\) | \(=\) | \(5\) |
| \(R\) | \(=\) | \(\min(9,\,5+3)=8\) |
| \(S\) | \(=\) | \(\min(5+8,\,8+4)=12\) |
| \(T\) | \(=\) | \(\min(8+10,\,12+2)=14\) |
| \(U\) | \(=\) | \(\min(12+9,\,14+5)=19\) |
Trace back from \(U\): \(U\) came from \(T\), \(T\) from \(S\), \(S\) from \(R\), \(R\) from \(Q\).
| \(P\text{-}Q\text{-}R\text{-}S\text{-}T\text{-}U\) | \(=\) | \(5+3+4+2+5\) |
| \(=\) | \(19\) |
\(\therefore\) the shortest path is \(P\)-\(Q\)-\(R\)-\(S\)-\(T\)-\(U\), \(\mathbf{19}\) km.
Use time \(=\dfrac{\text{distance}}{\text{speed}}\) for each route:
| \(\text{Suburbs: } t\) | \(=\) | \(\dfrac{22}{33}=\dfrac{2}{3}\text{ h}\) |
| \(=\) | \(\dfrac{2}{3}\times 60=40\text{ min}\) | |
| \(\text{Motorway: } t\) | \(=\) | \(\dfrac{30}{90}=\dfrac{1}{3}\text{ h}\) |
| \(=\) | \(\dfrac{1}{3}\times 60=20\text{ min}\) |
| \(40-20\) | \(=\) | \(20\text{ min}\) |
\(\therefore\) the motorway is quicker by \(\mathbf{20}\) minutes, even though it is \(8\text{ km}\) longer. The shortest path is not always the quickest.
(ii) The road between \(D\) and \(E\) is closed for repairs. Find the shortest path from \(A\) to \(G\) now.
(i) Label each town with its shortest distance from \(A\):
| \(B\) | \(=\) | \(5\) |
| \(C\) | \(=\) | \(\min(8,\,5+2)=7\) |
| \(D\) | \(=\) | \(\min(5+9,\,7+6)=13\) |
| \(E\) | \(=\) | \(\min(7+12,\,13+3)=16\) |
| \(F\) | \(=\) | \(\min(13+7,\,16+2)=18\) |
| \(G\) | \(=\) | \(\min(16+10,\,18+6)=24\) |
Path: \(A\)-\(B\)-\(C\)-\(D\)-\(E\)-\(F\)-\(G=5+2+6+3+2+6=24\)
\(\therefore\) the shortest path is \(\mathbf{24}\) km.
(ii) Remove edge \(DE\), then label again. \(B\), \(C\) and \(D\) do not change:
| \(E\) | \(=\) | \(7+12=19\) |
| \(F\) | \(=\) | \(\min(13+7,\,19+2)=20\) |
| \(G\) | \(=\) | \(\min(19+10,\,20+6)=26\) |
Without \(DE\), the closest way to reach \(E\) is from \(C\).
Path: \(A\)-\(B\)-\(C\)-\(D\)-\(F\)-\(G=5+2+6+7+6=26\)
\(\therefore\) with the road closed, the shortest path is \(\mathbf{26}\) km (\(2\text{ km}\) longer).
Common pitfalls
Frequently asked questions
How do you find the shortest path in a network?
For a small network, list the possible routes and add the weights along each one. For a bigger network, label each vertex with its shortest distance from the start, working outwards, then trace the path back from the finish.
Is the shortest path always the one with the fewest edges?
No. The length is the total of the weights, so a route with more edges can be shorter if its edges have smaller weights.
What does labelling the vertices mean?
Each vertex is given a number equal to its shortest distance from the start. A label is the smallest of (the label of a neighbouring labelled vertex + the weight of the edge between them), for example \(\min(5+9,\,7+6)=13\).
What is the difference between a shortest path and a minimum spanning tree?
A shortest path is the best route between two particular vertices. A minimum spanning tree is the cheapest set of edges that joins every vertex. They usually use different edges.
Is the shortest route always the quickest?
Not always. A longer route on faster roads can take less time. Work out time \(=\) distance \(\div\) speed for each route and compare.