Shortest Paths and Weighted Networks
Theory
In a weighted network each edge has a number: a distance, a time or a cost. This Year 10A maths page shows how to find the shortest path between two vertices, by comparing routes or by working out the shortest distance to each vertex in turn, and how to handle compulsory stops, closed roads and unknown weights.
A weighted network has a number, called a weight, on each edge. The weight might be a distance in km, a travel time in minutes or a cost in dollars.
The length (or weight) of a path is the sum of the weights of its edges. The shortest path between two vertices is the path with the smallest total. "Shortest" can mean quickest or cheapest, depending on the weights.
The shortest path is not always the direct edge, and not always the path with the fewest edges. Two short edges can beat one long one.
For small networks, list the routes and compare. For bigger networks, find the shortest distance from the start to each vertex in turn, closest first, and write it beside the vertex. The value at the finish is the answer, and tracing back gives the route.
Length of a path:
Shortest distance to a vertex \(V\) when it can be reached from \(X\) or \(Y\):
Comparing routes (small networks)
- List every sensible route from the start to the finish. Do not revisit a vertex.
- Add the weights along each route.
- Choose the smallest total, and name the route.
Working outwards (larger networks)
- Write \(0\) at the start.
- Label the vertex that is closest to the start with its shortest distance.
- Repeat: for each next vertex, add each edge weight to the label it comes from, and keep the smallest.
- Stop when the finish is labelled. Trace back along the edges that gave each smallest value to find the route.
List the sensible routes and add the weights.
| \(A - B - E\) | \(=\) | \(7 + 11 = 18\) |
| \(A - B - D - E\) | \(=\) | \(7 + 5 + 4 = 16\) |
| \(A - C - D - E\) | \(=\) | \(3 + 8 + 4 = 15\) |
| \(A - C - B - D - E\) | \(=\) | \(3 + 2 + 5 + 4 = \mathbf{14}\) |
The shortest path is \(A - C - B - D - E\), length 14. It has the most edges but the smallest total.
Find the shortest distance from \(S\) to each vertex in turn, closest first. At each vertex, take the smallest of the ways in.
| \(Q\) | \(=\) | \(1.2\) |
| \(P\) | \(=\) | \(\min(2.0,\ 1.2 + 0.6) = 1.8\) |
| \(U\) | \(=\) | \(\min(1.2 + 2.5,\ 1.8 + 2.0) = 3.7\) |
| \(R\) | \(=\) | \(\min(1.8 + 2.2,\ 3.7 + 0.7) = 4.0\) |
| \(T\) | \(=\) | \(\min(4.0 + 1.6,\ 3.7 + 2.4) = \mathbf{5.6}\) |
Trace back from \(T\): \(T \leftarrow R \leftarrow P \leftarrow Q \leftarrow S\). The route is \(S - Q - P - R - T\), 5.6 km.
(i) Find her quickest route and time.
(ii) How much time does the stop add?
(i) Split the trip at the shop and find the quickest way for each part.
| \(H \to S\) | \(\) | \(\min(9,\ 6 + 4) = 9\) |
| \(S \to B\) | \(\) | \(\min(15,\ 5 + 7,\ 4 + 7 + 7) = 12\) |
| \(\text{total}\) | \(=\) | \(9 + 12 = \mathbf{21}\text{ min}\) |
Route: \(H - S - K - B\).
(ii) Without the stop, the quickest is \(H - J - K - B = 6 + 7 + 7 = 20\) min. The stop adds 1 minute.
| \(P - R - Q\) | \(=\) | \(7 + 6 = 13\) |
| \(P - S - Q\) | \(=\) | \(5 + 9 = 14\) |
For the route through \(R\) to be the shortest, the direct road must be longer than \(13\).
| \(x\) | \(>\) | \(13\) |
| \(x\) | \(=\) | \(\mathbf{14}\ \text{(smallest whole number)}\) |
Check: with \(x = 13\) the direct road would tie with \(P - R - Q\), so \(13\) does not work.
Common pitfalls
Frequently asked questions
How do you find the shortest path in a network?
For a small network, list the possible routes, add the weights on each, and choose the smallest total. For a larger network, find the shortest distance from the start to each vertex in turn until you reach the finish.
What is a weighted network?
A network where every edge has a number on it, such as a distance, a time or a cost. The weight of a path is the sum of the numbers on its edges.
Is the shortest path always the one with the fewest edges?
No. A path with more edges can have a smaller total if those edges are short. Always add the weights.
How do you find the shortest path if you must stop somewhere on the way?
Split the trip at the stop. Find the shortest path from the start to the stop and from the stop to the finish, then add them.
What happens to the shortest path if a road is closed?
Remove that edge and find the shortest path again. It stays the same if the closed road was not on it; otherwise the new shortest path is the same length (if another route tied) or longer.