How is the shortest path between two vertices in a weighted network found?
Find the shortest path between two vertices in a weighted network by inspection or by systematic labelling
A focused answer to the HSC Maths Standard 2 dot point on shortest paths. Inspection method for small networks, systematic labelling for larger ones, and worked examples for road network distances and Sydney transport routes.
Have a quick question? Jump to the Q&A page
What this dot point is asking
NESA wants you to find the shortest path between two specified vertices in a weighted network. For small networks, inspection (listing all reasonable paths and picking the smallest) is enough. For larger ones, a systematic labelling method like Dijkstra's algorithm is expected.
The answer
What the question asks
Given a weighted graph with vertices and edge weights (distances, times, costs), find the path from a starting vertex to an ending vertex with the smallest total weight.
The shortest path may not be the path with the fewest edges. A long edge with low weight per edge can sometimes be faster than a short path with high weights.
Method 1: inspection
For small networks (say vertices or fewer), list all sensible candidate paths between the start and end vertex, compute each total weight, and pick the smallest.
This works when:
- The graph is small.
- There are few branching options.
- You can spot all reasonable paths visually.
Method 2: systematic labelling (Dijkstra's algorithm)
For larger networks, use systematic labelling:
- Label the start vertex with . Label all other vertices with (or just "unknown").
- From the current vertex (start with the start), look at each neighbour and compute the proposed label = current label + edge weight. If this is less than the neighbour's current label, update.
- Mark the current vertex as finalised.
- Move to the unfinalised vertex with the smallest current label.
- Repeat steps 2-4 until the end vertex is finalised.
The final label on the end vertex is the shortest total weight. Trace back through the predecessors to find the actual path.
Tracking the path
While labelling, record the predecessor: which vertex you came from when you set the current label. After finishing, trace backwards from the end vertex to the start using these predecessors, then reverse to get the path in forward order.
Equal-weight ties
If two paths have the same total weight, there are multiple shortest paths. State both (or all) in your answer.
Sanity checks
- Total weight on the path equals the final label on the end vertex.
- Each edge used was an actual edge in the graph.
- The path is connected: each consecutive pair of vertices is joined by an edge.
Past exam questions, worked
Real questions from past NESA papers on this dot point, with our answer explainer.
2022 HSC Q244 marksIn a road network with vertices and weighted edges representing distances in km, find the shortest path from to and state its length.Show worked answer β
List all possible paths from to and their lengths.
Say the paths are: -- (length ), -- (length ), --- (length ), --- (length ).
The shortest is km, via either --- or --- (both give the same length).
Markers reward listing the candidate paths systematically, computing each total, identifying the shortest, and noting if multiple paths tie. State all tied shortest paths if asked.
2023 HSC Q234 marksA driver in Sydney wants the shortest route from her home (vertex ) to her workplace (vertex ) using a weighted graph where edges are road segments and weights are typical drive times in minutes. Find the shortest route and its total time.Show worked answer β
Apply systematic labelling: starting at , label each vertex with the shortest known total time from . Update labels as shorter paths are found.
Step through: label with . Label its neighbours with the edge weights to them. From the next vertex with the smallest label, update its neighbours, and so on, always taking the smallest unfinalised label next.
Continue until is labelled. The final label on is the shortest total time. Trace back via the predecessors to find the actual route.
Markers reward systematic application of the labelling, accurate intermediate values, the shortest time, and the route traced back. State the route as a sequence of vertices and the total time with units.
Related dot points
- Use network terminology including vertex, edge, weight, degree, path, cycle and directed graph to describe and analyse networks
A focused answer to the HSC Maths Standard 2 dot point on network terminology. Vertices, edges, weights, directed and undirected graphs, paths and cycles, connected and disconnected components, and worked Australian examples for transport networks and project schedules.
- Find a minimum spanning tree for a weighted graph using Prim's or Kruskal's algorithm
A focused answer to the HSC Maths Standard 2 dot point on minimum spanning trees. Definition of a spanning tree and minimum spanning tree, step-by-step Prim's and Kruskal's algorithms, and worked examples for utility networks and rural Australian infrastructure planning.
- Construct an activity network from a precedence table, identify the critical path and find the minimum project duration
A focused answer to the HSC Maths Standard 2 dot point on critical path analysis. Building an activity network from a precedence table, identifying paths through the network, and determining the minimum project duration via the critical (longest) path with worked Australian construction examples.