Walks, trails, paths and the shortest path
Learn to describe and compare routes through a network in Year 12 General Mathematics for Queensland (QCAA). Whether it is a courier crossing Brisbane, a bushwalker choosing tracks on Fraser Island (K’gari) or data moving through cables, the important questions are the same: can you get there, which links are critical, and which way is quickest?
You will learn the difference between a walk, a trail, a path and a cycle, decide whether a graph is connected and find any bridges. Then you will find the shortest path in a weighted network by listing the possible routes and comparing totals, ready for Eulerian trails and circuits in the next subtopic.
Theory
Routes through a network have precise names. This Year 12 General Mathematics guide for Queensland students explains walks, open and closed trails, paths and cycles, what makes a graph connected, how to spot a bridge, and how to find the shortest path in a weighted network by listing and comparing routes.
A walk is a route through a graph: a list of vertices, each joined to the next by an edge. In a walk, vertices and edges may be repeated. A trail is a walk that never uses the same edge twice (vertices may repeat). A trail is open if it starts and finishes at different vertices and closed if it returns to its start. A closed trail is also called a circuit.
A path is a walk that never visits the same vertex twice, so it cannot repeat an edge either. An open path starts and finishes at different vertices. A closed path, which returns to its start with no other vertex repeated, is a cycle. So every path is a trail, and every trail is a walk.
A graph is connected if there is a path between every pair of vertices. A bridge is an edge that, if removed, would leave a connected graph disconnected. In a weighted graph the length of a route is the total of its edge weights, and the shortest path from one vertex to another is the path with the smallest total.
The length (weight) of a route is the total of the weights of the edges it uses:
How to name a route:
| Route | Repeated edge? | Repeated vertex? | Starts and ends at the same vertex? |
|---|---|---|---|
| walk | allowed | allowed | either |
| open trail | no | allowed | no |
| closed trail (circuit) | no | allowed | yes |
| open path | no | no | no |
| cycle (closed path) | no | only the start = end | yes |
How to find the shortest path by trial and error
- Mark the start and finish. Look at the edges leaving the start and arriving at the finish.
- List the paths. Write down each path from start to finish that does not revisit a vertex. Work systematically, for example by the first edge used, so none are missed.
- Total each path, one path per line. Skip a path as soon as its running total passes the best total found so far.
- Compare and answer. Give the shortest path as a list of vertices and its length with units. Check that every edge you used really exists.
For bigger networks, a step-by-step method such as Dijkstra’s algorithm does the same job, but careful listing is enough for the small networks met here.
Check for a repeated edge first, then a repeated vertex, then whether the route is closed.
| \(A\text{-}B\text{-}E\text{-}F\text{-}A\) | \(:\) | \(\text{cycle}\) |
| \(A\text{-}B\text{-}C\text{-}D\text{-}E\text{-}B\text{-}A\) | \(:\) | \(\text{walk}\) |
| \(F\text{-}A\text{-}B\text{-}E\text{-}D\text{-}C\text{-}B\) | \(:\) | \(\text{open trail}\) |
| \(C\text{-}D\text{-}E\text{-}F\) | \(:\) | \(\text{open path}\) |
(i) Only \(A\) repeats, as the start and end: a cycle. (ii) Edge \(AB\) is used twice: only a walk. (iii) \(B\) is visited twice but no edge repeats, and it ends at a different vertex: an open trail. (iv) Nothing repeats: an open path.
Test each edge: would removing it cut some substations off from the rest?
| \(\text{remove } RS\) | \(:\) | \(\{P, Q, R\} \text{ cut off}\) |
| \(\text{remove } UV\) | \(:\) | \(V \text{ cut off}\) |
| \(\text{remove } ST\) | \(:\) | \(S\text{-}U\text{-}T \text{ still joins them}\) |
(i) Yes. There is a path between every pair of substations. (ii) \(RS\) and \(UV\) are bridges. Every other line lies on a triangle, so there is another way round if it is removed.
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 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.
Common pitfalls
Frequently asked questions
What is the difference between a walk, a trail and a path?
A walk is any route along edges, and it may repeat vertices and edges. A trail is a walk with no repeated edge. A path is a walk with no repeated vertex, so it cannot repeat an edge either.
What is a cycle in a graph?
A cycle is a closed path. It starts and finishes at the same vertex and no other vertex is repeated. A closed trail that passes through some vertex twice is a circuit but not a cycle.
What is a bridge in a graph?
A bridge is an edge whose removal would split a connected graph into two separate parts. An edge that lies on a cycle is never a bridge, because there is another way round.
How do you find the shortest path in a network?
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.
Do I need Dijkstra's algorithm to find a shortest path?
No. For small networks, listing the paths and comparing their totals (trial and error) is enough. Dijkstra's algorithm is one systematic method that gives the same answer for larger networks.
What does it mean for a graph to be connected?
A graph is connected if you can travel from any vertex to any other vertex along its edges. If some vertex cannot be reached, the graph is disconnected.