Skip to main content
ExamExplained
NSW · Maths Standard 2
Maths Standard 2 study scene
§-Syllabus dot point
NSWMaths Standard 2Syllabus dot point

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 for small networks, systematic labelling (Dijkstra-style) for larger ones, a stage-by-stage walkthrough, ties and verification edge cases, and worked road and Sydney transport examples.

Reviewed by: AI editorial process; not yet individually human-reviewed

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 named vertices in a weighted network. For small networks, inspection is enough: list all the reasonable paths and pick the smallest total. For larger ones, a systematic labelling method (Dijkstra's algorithm) is expected. Once a graph has more than a handful of vertices, this is the method markers prefer to see.

"Shortest" means smallest total weight, whatever the weight represents: distance in km, drive time in minutes, or cost in dollars. The method is identical in each case; only the units change.

The answer

Weighted graph with the shortest path from A to D highlighted A weighted undirected graph with vertices A, B, C, D. Edge weights are AB 3, AC 5, BC 1, BD 6, CD 2. The shortest path from A to D runs A to B to C to D, drawn in the heavier accent colour, with total length 3 plus 1 plus 2, which is 6. The other edges AC and BD are drawn muted. 3 1 2 5 6 A B C D Shortest path A to B to C to D, total 3 + 1 + 2 = 6 (accent). AC and BD are longer.

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 route built from several small-weight edges can beat a direct route across one large-weight edge, which is exactly why the diagram above takes three edges (AA-BB-CC-DD, total 66) rather than the two-edge route AA-CC-DD, which totals 77.

Method 1: inspection

For small networks (say 55 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 every reasonable path visually.

The risk with inspection is missing a path, so be systematic: fix the first step out of the start vertex, exhaust every route that begins that way, then move to the next first step. A path should never revisit a vertex, because looping back only adds weight and can never shorten a route.

Method 2: systematic labelling (Dijkstra's algorithm)

For larger networks, use systematic labelling. The idea is to give every vertex a running label equal to the shortest distance found so far from the start, then lock in (finalise) vertices one at a time in increasing order of distance:

  1. Label the start vertex with 00. Label all other vertices with \infty (or just "unknown").
  2. From the current vertex, look at each neighbour and compute the proposed label as current label + edge weight. If this is less than the neighbour's current label, update it (and record the predecessor).
  3. Mark the current vertex as finalised; its label will not change again.
  4. Move to the unfinalised vertex with the smallest current label.
  5. Repeat steps 2 to 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.

Why do you always finalise (lock in) the smallest unfinalised label? Because nothing left in the graph can reach it for less. Any other route to it would first pass through a vertex whose label is the same or bigger. All the edge weights are positive, so going that way can only add more. That is why a locked-in label never needs to change again.

Tracking the path

While labelling, record the predecessor: which vertex you came from when you set (or last improved) 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. Without the predecessors you get the shortest distance but cannot name the shortest route, and most questions ask for both.

Find the shortest path, stage by stage

The diagram below is run one settled vertex at a time, so you can see exactly where every label comes from. The network has vertices AA to EE; we want the shortest path from AA to EE. Each vertex carries its running shortest distance from AA (the start). A vertex with an accent ring has been settled: its label is final and will not change.

Stage 1, settle the start and label its neighbours. Set A=0A = 0 and settle it. Look at the edges leaving AA: AA-BB has weight 22, so BB gets the tentative label 22; AA-CC has weight 44, so CC gets 44. Vertices DD and EE are not yet reachable, so they stay at \infty.

Settle the start vertex A at distance 0Weighted graph with vertices A, B, C, D, E. A is settled at running distance 0. Its neighbours are given tentative distances: B is 2 and C is 4. All other vertices are still infinity. The settled vertex A has an accent ring.2417352ABCDE024Stage 1Stage 1: A is settled at 0. Tentative labels B = 2, C = 4 from A.D and E are still unknown.

Stage 2, settle the smallest label and relax its neighbours. The smallest unfinalised label is B=2B = 2, so settle BB. Now check BB's neighbours. The route to CC via BB is 2+1=32 + 1 = 3, which beats CC's current 44, so update CC to 33 (its predecessor becomes BB). The route to DD via BB is 2+7=92 + 7 = 9, so DD becomes 99. This relaxation step, replacing a label when a shorter route appears, is the heart of the method.

Settle B, the smallest tentative labelThe same graph. B, the smallest tentative label at 2, is now settled with an accent ring. From B the label on C improves from 4 to 3 via A to B to C, 2 plus 1, and D becomes 9. C now reads 3 and D reads 9.2417352ABCDE0239Stage 2Stage 2: settle B (smallest label, 2). From B, update C to 2 + 1 = 3and set D to 2 + 7 = 9. The 3 beats C's old 4, so C improves.

Stage 3, settle C, then settle D. The smallest unfinalised label is now C=3C = 3, so settle CC. From CC: the route to DD is 3+3=63 + 3 = 6, beating DD's current 99, so update DD to 66; the route to EE is 3+5=83 + 5 = 8, so EE becomes 88. The next smallest unfinalised label is D=6D = 6, so settle it; the route DD-EE would give 6+2=86 + 2 = 8, which ties EE's existing 88, so EE stays at 88 (we keep the route already recorded).

Settle C, then DThe same graph. C is settled at 3. From C the label on D improves from 9 to 6, 3 plus 3, and E becomes 8, 3 plus 5. Then D, now the smallest at 6, is settled; the route D to E would give 6 plus 2 = 8, which ties E's existing 8, so E stays 8. C and D have accent rings.2417352ABCDE02368Stage 3Stage 3: settle C (3). Update D to 3 + 3 = 6 and E to 3 + 5 = 8.Then settle D (6); D to E gives 6 + 2 = 8, a tie, so E stays 8.

Stage 4, settle the end vertex and trace the path back. The only label left is E=8E = 8, so settle it; the algorithm is done. Now trace back using predecessors: EE was set from CC (3+5=83 + 5 = 8), CC was set from BB (2+1=32 + 1 = 3), and BB came from AA. Reversed, the shortest path is AA-BB-CC-EE with total 2+1+5=82 + 1 + 5 = 8. Note the tie spotted in stage 3: the route AA-BB-CC-DD-EE also totals 2+1+3+2=82 + 1 + 3 + 2 = 8, so there are two equally short paths.

Settle E and trace the shortest pathThe same graph with the shortest path from A to E highlighted in the heavier accent colour: A to B to C to E, weights 2, 1 and 5 giving total 8. E is settled at 8. The edges A to B, B to C and C to E are accent; the alternative tie via D is noted in the caption.2417352ABCDE02368Stage 4Stage 4: E settles at 8. Trace back E from C, C from B, B from A:shortest path A-B-C-E = 2 + 1 + 5 = 8. A-B-C-D-E also totals 8 (a tie).

Laid out as a running table, the four stages are:

Settle AA BB CC DD EE
Start 00 \infty \infty \infty \infty
AA 0\mathbf{0} 22 44 \infty \infty
BB 0\mathbf{0} 2\mathbf{2} 33 99 \infty
CC 0\mathbf{0} 2\mathbf{2} 3\mathbf{3} 66 88
DD 0\mathbf{0} 2\mathbf{2} 3\mathbf{3} 6\mathbf{6} 88
EE 0\mathbf{0} 2\mathbf{2} 3\mathbf{3} 6\mathbf{6} 8\mathbf{8}

A bold entry is a settled (final) label. Reading down a column shows how a vertex's label can fall (for example CC drops from 44 to 33, and DD from 99 to 66) but never rises, and never changes once bold.

Equal-weight ties

If two paths have the same total weight, there are multiple shortest paths, and the run above is a clean example: AA-BB-CC-EE and AA-BB-CC-DD-EE both total 88. Systematic labelling reports only one of them (whichever it recorded first), so a tie is easy to miss. When a question asks for "the" shortest path and a tie exists, state every tied route; when it asks only for the shortest distance, the single value 88 is enough. The tell-tale sign of a tie is the moment in stage 3 where the route DD-EE re-derives EE's existing label exactly rather than beating it.

Checking you have not missed a shorter route

The most common worry with inspection is "could there be a shorter path I did not list?" Three checks settle it:

  • Cross-check inspection against labelling. If a small graph gives the same answer by both methods, you can be confident. The worked example below does exactly this.
  • Confirm the total equals the end label. The summed weights along your chosen path must equal the final label on the end vertex. If they disagree, you have either mis-added or mis-traced the predecessors.
  • Confirm every cheaper first move was explored. A shorter route would have to leave the start along a cheaper edge or reach the end through a vertex with a smaller settled label. Because labelling settles vertices in increasing order, anything cheaper was already locked in earlier, so nothing shorter can remain.

Directed versus undirected edges

In Standard 2, road and transport networks are usually undirected. That means an edge between XX and YY can be travelled either way for the same weight, so XX-YY and YY-XX cost the same. Sometimes a question uses directed edges, which are edges with arrows. A one-way street is one example, or a route where the uphill and downhill times differ. The method does not change, but there is one extra rule: when you update a vertex's neighbours, only follow edges the way their arrow points. On a directed graph, the shortest path from AA to EE may differ from the shortest path from EE to AA. So read the arrows before you start, and keep to them the whole way through.

Sanity checks

  • Total weight on the path equals the final label on the end vertex.
  • Each edge used is an actual edge in the graph (and, if directed, used the right way).
  • The path is connected: each consecutive pair of vertices is joined by an edge.
  • No vertex is visited twice; a repeat means a loop has crept in.

How exam questions ask about shortest paths

The wording varies, but every version reduces to the same task. Learn to translate it:

  • "Find the shortest path / shortest route from XX to YY." Give the path as a sequence of vertices and its total weight with units. The route, not just the number, is required.
  • "Find the shortest distance / least time / cheapest cost from XX to YY." The total weight is the headline answer; still show the route as method.
  • "Show your working", or a 44-plus mark question on a larger graph. Use systematic labelling and show the labels (a running table is ideal); inspection without working can lose method marks once the graph is non-trivial.
  • "Is there more than one shortest path?" A tie question: list every route that achieves the minimum total.
  • "Explain why this route is shortest." Point to the labelling: the end vertex was settled at that value, and no unsettled vertex had a smaller label, so no shorter route exists.
  • "One road is closed, or a new road opens." Re-run the affected part: delete or add the edge, then recompute. Often only one or two labels change.

One distinction is worth a mark. A question that says "connect all the towns with the least total road length" is a minimum spanning tree problem, not a shortest path. A shortest path runs point to point between two named vertices. A minimum spanning tree (MST) instead joins up every vertex. Decide which one is being asked before you start.

Exam-style practice questions

Practice questions written in the style of NESA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

2022 HSC-style4 marksIn a road network with vertices A,B,C,D,EA, B, C, D, E and weighted edges representing distances in km, find the shortest path from AA to EE and state its length.
Show worked answer →

List all possible paths from AA to EE and their lengths.

Say the paths are: AA-BB-EE (length 4+8=124 + 8 = 12), AA-CC-EE (length 5+6=115 + 6 = 11), AA-CC-DD-EE (length 5+3+2=105 + 3 + 2 = 10), AA-BB-DD-EE (length 4+4+2=104 + 4 + 2 = 10).

The shortest is 1010 km, via either AA-CC-DD-EE or AA-BB-DD-EE (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-style4 marksA driver in Sydney wants the shortest route from her home (vertex HH) to her workplace (vertex WW) 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 HH, label each vertex with the shortest known total time from HH. Update labels as shorter paths are found.

Step through: label HH with 00. 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 WW is labelled. The final label on WW 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.

Practice questions

Original practice questions graded from foundation to exam level, each with a full worked solution. Try them before revealing the solution.

foundation1 marksA small network has three towns AA, BB and CC. The roads (distances in km) are AA-BB of length 44, BB-CC of length 33, and a direct road AA-CC of length 99. Find the shortest path from AA to CC and state its total length.
Show worked solution →
List the routes from AA to CC
With only three towns there are two simple paths: the direct road AA-CC, and the route through BB, AA-BB-CC.
Add up each total
Direct: AA-CC is 99 km. Via BB: AA-BB-CC is 4+3=74 + 3 = 7 km.
Pick the smaller total
7<97 < 9, so the route through BB wins.
Answer
the shortest path is AA-BB-CC with total length 77 km. (Check: the only alternative, the direct road AA-CC, is 99 km, which is longer, so 77 km is the minimum.)
foundation2 marksA delivery van travels on a network of four suburbs PP, QQ, RR, SS. The road segments (drive time in minutes) are PP-QQ of 66, QQ-RR of 55, RR-SS of 44, and a direct freeway PP-SS of 2020. Find the shortest route from PP to SS and state its total time.
Show worked solution →
Identify the candidate routes
From PP to SS there are two simple paths: the freeway PP-SS, and the chain PP-QQ-RR-SS.
Total each route
Freeway: PP-SS is 2020 minutes. Chain: PP-QQ-RR-SS is 6+5+4=156 + 5 + 4 = 15 minutes.
Choose the smaller
The chain at 1515 minutes beats the freeway at 2020 minutes, even though it uses three roads instead of one.
Answer
the shortest route is PP-QQ-RR-SS, taking 1515 minutes. (Check: the only other route, the direct freeway, is 2020 minutes, which is longer, so 1515 minutes is the least.)
foundation2 marksA cyclist rides on a network with vertices AA, BB, CC, DD. The paths (distances in km) are AA-BB of 22, BB-CC of 22, CC-DD of 33, and a direct path AA-DD of 1010. Find the shortest path from AA to DD and explain why it uses more edges than the direct path.
Show worked solution →
Find the candidate paths
From AA to DD there are two simple routes: the direct path AA-DD, and the longer chain AA-BB-CC-DD.
Total each one
Direct: AA-DD is 1010 km. Chain: AA-BB-CC-DD is 2+2+3=72 + 2 + 3 = 7 km.
Compare
7<107 < 10, so the three-edge chain is shorter than the single direct edge.
Why the longer-looking route wins
"Shortest path" means least total weight, not fewest edges. The three small edges (22, 22, 33) add to less than the one big edge of 1010.
Answer
the shortest path is AA-BB-CC-DD at 77 km. (Check: the only alternative, AA-DD, is 1010 km, confirming 77 km is the minimum.)
foundation2 marksA commuter chooses between routes from home HH to work WW on a toll network, where each weight is the cost in dollars. The roads are HH-MM of 77, MM-WW of 66, HH-KK of 55 and KK-WW of 66. Find the cheapest route from HH to WW and state its total cost.
Show worked solution →
List the routes
Two simple paths run from HH to WW: HH-MM-WW and HH-KK-WW.
Total each cost
Via MM: HH-MM-WW is 7+6=137 + 6 = 13 dollars. Via KK: HH-KK-WW is 5+6=115 + 6 = 11 dollars.
Pick the cheaper
11<1311 < 13, so the route through KK is cheaper.
Answer
the cheapest route is HH-KK-WW at a total cost of 1111 dollars. (Check: the only alternative, HH-MM-WW, costs 1313 dollars, which is more, so 1111 dollars is the minimum.)
core3 marksA road network has vertices AA, BB, CC, DD, EE with edge distances (km): AA-BB of 33, AA-CC of 66, BB-CC of 22, BB-DD of 55, CC-DD of 44, DD-EE of 33, CC-EE of 99. Find the shortest path from AA to EE and state its total length.
Show worked solution →
Set up systematic labelling from AA
Label A=0A = 0. Its neighbours: B=0+3=3B = 0 + 3 = 3 and C=0+6=6C = 0 + 6 = 6. Settle AA.
Settle the smallest label, B=3B = 3
From BB: CC becomes min(6,  3+2)=5\min(6, \; 3 + 2) = 5 (predecessor BB); D=3+5=8D = 3 + 5 = 8. Settle BB.
Settle C=5C = 5
From CC: DD becomes min(8,  5+4)=8\min(8, \; 5 + 4) = 8 (no change, keep predecessor BB); E=5+9=14E = 5 + 9 = 14. Settle CC.
Settle D=8D = 8
From DD: EE becomes min(14,  8+3)=11\min(14, \; 8 + 3) = 11 (predecessor DD). Settle DD, then settle E=11E = 11.
Trace back
EE from DD, DD from BB, BB from AA: the path is AA-BB-DD-EE.
Answer
shortest path AA-BB-DD-EE, total 3+5+3=113 + 5 + 3 = 11 km. (Check: AA-BB-CC-DD-EE gives 3+2+4+3=123 + 2 + 4 + 3 = 12 km, which is longer, so 1111 km is the minimum.)
core3 marksA driver crosses a town network with vertices AA, BB, CC, DD, EE, where weights are drive times in minutes: AA-BB of 99, AA-CC of 44, CC-BB of 22, BB-DD of 66, CC-DD of 1111, DD-EE of 33, BB-EE of 1212. Find the shortest route from AA to EE and state its total time.
Show worked solution →
Label from AA
Set A=0A = 0. Neighbours: B=9B = 9 and C=4C = 4. Settle AA.
Settle the smallest, C=4C = 4
From CC: BB becomes min(9,  4+2)=6\min(9, \; 4 + 2) = 6 (predecessor CC); D=4+11=15D = 4 + 11 = 15. Settle CC.
Settle B=6B = 6
From BB: DD becomes min(15,  6+6)=12\min(15, \; 6 + 6) = 12 (predecessor BB); E=6+12=18E = 6 + 12 = 18. Settle BB.
Settle D=12D = 12
From DD: EE becomes min(18,  12+3)=15\min(18, \; 12 + 3) = 15 (predecessor DD). Settle DD, then settle E=15E = 15.
Trace back
EE from DD, DD from BB, BB from CC, CC from AA: the route is AA-CC-BB-DD-EE.
Answer
shortest route AA-CC-BB-DD-EE, total 4+2+6+3=154 + 2 + 6 + 3 = 15 minutes. (Check: the direct-looking AA-BB-DD-EE gives 9+6+3=189 + 6 + 3 = 18 minutes, which is longer, so 1515 minutes is the minimum.)
core4 marksA courier uses a network from depot SS to drop-off TT with vertices SS, AA, BB, CC, TT and edge times (minutes): SS-AA of 44, SS-BB of 66, AA-BB of 11, AA-CC of 88, BB-CC of 55, CC-TT of 33, BB-TT of 1212. (a) Find the shortest route from SS to TT and its total time. (b) The road CC-TT is closed for works; find the new shortest route and time.
Show worked solution →

Part (a), label from SS. Set S=0S = 0. Neighbours: A=4A = 4, B=6B = 6. Settle SS.

Settle A=4A = 4. From AA: BB becomes min(6,  4+1)=5\min(6, \; 4 + 1) = 5 (predecessor AA); C=4+8=12C = 4 + 8 = 12. Settle AA.

Settle B=5B = 5. From BB: CC becomes min(12,  5+5)=10\min(12, \; 5 + 5) = 10 (predecessor BB); T=5+12=17T = 5 + 12 = 17. Settle BB.

Settle C=10C = 10. From CC: TT becomes min(17,  10+3)=13\min(17, \; 10 + 3) = 13 (predecessor CC). Settle CC, then T=13T = 13.

Trace back
TT from CC, CC from BB, BB from AA, AA from SS, giving SS-AA-BB-CC-TT, total 4+1+5+3=134 + 1 + 5 + 3 = 13 minutes.
Part (b), delete CC-TT and re-solve
With CC-TT gone, the only way into TT is BB-TT. The labels up to B=5B = 5 are unchanged, so T=5+12=17T = 5 + 12 = 17 via SS-AA-BB-TT.
Answers
(a) SS-AA-BB-CC-TT, 1313 minutes; (b) SS-AA-BB-TT, 1717 minutes. (Check (a): SS-BB-CC-TT gives 6+5+3=146 + 5 + 3 = 14 minutes, longer than 1313. Check (b): SS-BB-TT gives 6+12=186 + 12 = 18 minutes, longer than 1717.)
core4 marksA network of paths has vertices AA, BB, CC, DD, EE, FF with distances (km): AA-BB of 22, AA-CC of 55, BB-CC of 22, BB-DD of 77, CC-DD of 11, CC-EE of 44, DD-EE of 33, DD-FF of 66, EE-FF of 55. Find the shortest path from AA to FF and state its total length.
Show worked solution →
Label from AA
Set A=0A = 0. Neighbours: B=2B = 2, C=5C = 5. Settle AA.
Settle B=2B = 2
From BB: CC becomes min(5,  2+2)=4\min(5, \; 2 + 2) = 4 (predecessor BB); D=2+7=9D = 2 + 7 = 9. Settle BB.
Settle C=4C = 4
From CC: DD becomes min(9,  4+1)=5\min(9, \; 4 + 1) = 5 (predecessor CC); E=4+4=8E = 4 + 4 = 8. Settle CC.
Settle D=5D = 5
From DD: EE becomes min(8,  5+3)=8\min(8, \; 5 + 3) = 8 (no change); F=5+6=11F = 5 + 6 = 11 (predecessor DD). Settle DD.
Settle E=8E = 8
From EE: FF becomes min(11,  8+5)=11\min(11, \; 8 + 5) = 11 (no change). Settle EE, then F=11F = 11.
Trace back
FF from DD, DD from CC, CC from BB, BB from AA: path AA-BB-CC-DD-FF.
Answer
shortest path AA-BB-CC-DD-FF, total 2+2+1+6=112 + 2 + 1 + 6 = 11 km. (Check: AA-CC-DD-FF gives 5+1+6=125 + 1 + 6 = 12 km, longer, so 1111 km is the minimum.)
exam4 marksA network has vertices AA, BB, CC, DD, EE, FF with edge weights (minutes): AA-BB of 22, AA-CC of 66, BB-CC of 33, BB-DD of 44, CC-DD of 22, DD-EE of 33, EE-FF of 33, DD-FF of 66. Find the shortest path from AA to FF, state its total time, and say whether more than one shortest path exists.
Show worked solution →
Label from AA
Set A=0A = 0. Neighbours: B=2B = 2, C=6C = 6. Settle AA.
Settle B=2B = 2
From BB: CC becomes min(6,  2+3)=5\min(6, \; 2 + 3) = 5 (predecessor BB); D=2+4=6D = 2 + 4 = 6 (predecessor BB). Settle BB.
Settle C=5C = 5
From CC: DD becomes min(6,  5+2)=6\min(6, \; 5 + 2) = 6 (no change, keep predecessor BB). Settle CC.
Settle D=6D = 6
From DD: E=6+3=9E = 6 + 3 = 9; F=6+6=12F = 6 + 6 = 12 (predecessor DD). Settle DD.
Settle E=9E = 9
From EE: FF becomes min(12,  9+3)=12\min(12, \; 9 + 3) = 12. This re-derives F=12F = 12 exactly rather than beating it, the tell-tale sign of a tie. Settle EE, then F=12F = 12.
Trace back the two routes
Direct from DD: AA-BB-DD-FF is 2+4+6=122 + 4 + 6 = 12. Via EE: AA-BB-DD-EE-FF is 2+4+3+3=122 + 4 + 3 + 3 = 12.
Answer
the shortest time is 1212 minutes, and there are two shortest paths, AA-BB-DD-FF and AA-BB-DD-EE-FF, since both total 1212. (Check: the next best route AA-BB-CC-DD-FF gives 2+3+2+6=132 + 3 + 2 + 6 = 13 minutes, longer than 1212.)
exam5 marksA regional road network has towns AA, BB, CC, DD, EE, FF, GG with distances (km): AA-BB of 44, AA-CC of 33, BB-CC of 11, BB-DD of 99, CC-DD of 55, CC-EE of 88, DD-EE of 22, DD-FF of 66, EE-FF of 33, EE-GG of 1010, FF-GG of 22. Find the shortest path from AA to GG and state its total length.
Show worked solution →
Label from AA
Set A=0A = 0. Neighbours: B=4B = 4, C=3C = 3. Settle AA.
Settle C=3C = 3
From CC: BB becomes min(4,  3+1)=4\min(4, \; 3 + 1) = 4 (no change); D=3+5=8D = 3 + 5 = 8; E=3+8=11E = 3 + 8 = 11. Settle CC.
Settle B=4B = 4
From BB: DD becomes min(8,  4+9)=8\min(8, \; 4 + 9) = 8 (no change). Settle BB.
Settle D=8D = 8
From DD: EE becomes min(11,  8+2)=10\min(11, \; 8 + 2) = 10 (predecessor DD); F=8+6=14F = 8 + 6 = 14. Settle DD.
Settle E=10E = 10
From EE: FF becomes min(14,  10+3)=13\min(14, \; 10 + 3) = 13 (predecessor EE); G=10+10=20G = 10 + 10 = 20. Settle EE.
Settle F=13F = 13
From FF: GG becomes min(20,  13+2)=15\min(20, \; 13 + 2) = 15 (predecessor FF). Settle FF, then G=15G = 15.
Trace back
GG from FF, FF from EE, EE from DD, DD from CC, CC from AA: path AA-CC-DD-EE-FF-GG.
Answer
shortest path AA-CC-DD-EE-FF-GG, total 3+5+2+3+2=153 + 5 + 2 + 3 + 2 = 15 km. (Check: AA-CC-DD-FF-GG gives 3+5+6+2=163 + 5 + 6 + 2 = 16 km, longer, so 1515 km is the minimum.)
exam5 marksA one-way courier network has directed edges (drive time in minutes), each travelled only in the stated direction: AA to BB of 33, AA to CC of 55, BB to CC of 11, BB to DD of 66, CC to DD of 22, CC to EE of 99, DD to EE of 33, DD to FF of 88, EE to FF of 22. Find the shortest directed route from AA to FF and state its total time.
Show worked solution →
Label from AA, following arrows only
Set A=0A = 0. Out-edges of AA: B=3B = 3, C=5C = 5. Settle AA.
Settle B=3B = 3
Out-edges of BB: CC becomes min(5,  3+1)=4\min(5, \; 3 + 1) = 4 (predecessor BB); D=3+6=9D = 3 + 6 = 9. Settle BB.
Settle C=4C = 4
Out-edges of CC: DD becomes min(9,  4+2)=6\min(9, \; 4 + 2) = 6 (predecessor CC); E=4+9=13E = 4 + 9 = 13. Settle CC.
Settle D=6D = 6
Out-edges of DD: EE becomes min(13,  6+3)=9\min(13, \; 6 + 3) = 9 (predecessor DD); F=6+8=14F = 6 + 8 = 14. Settle DD.
Settle E=9E = 9
Out-edge of EE: FF becomes min(14,  9+2)=11\min(14, \; 9 + 2) = 11 (predecessor EE). Settle EE, then F=11F = 11.
Trace back
FF from EE, EE from DD, DD from CC, CC from BB, BB from AA: route AA-BB-CC-DD-EE-FF.
Answer
shortest directed route AA-BB-CC-DD-EE-FF, total 3+1+2+3+2=113 + 1 + 2 + 3 + 2 = 11 minutes. (Check: AA-CC-DD-EE-FF gives 5+2+3+2=125 + 2 + 3 + 2 = 12 minutes, longer, so 1111 minutes is the minimum; arrows were followed throughout.)
exam5 marksA logistics network has hubs AA, BB, CC, DD, EE, FF, GG with edge costs (dollars): AA-BB of 55, AA-CC of 44, BB-CC of 22, BB-DD of 66, CC-DD of 33, CC-EE of 88, DD-EE of 22, DD-FF of 77, EE-FF of 33, EE-GG of 44, FF-GG of 22, DD-GG of 1010. Find the cheapest route from AA to GG and state its total cost.
Show worked solution →
Label from AA
Set A=0A = 0. Neighbours: B=5B = 5, C=4C = 4. Settle AA.
Settle C=4C = 4
From CC: BB becomes min(5,  4+2)=5\min(5, \; 4 + 2) = 5 (no change); D=4+3=7D = 4 + 3 = 7; E=4+8=12E = 4 + 8 = 12. Settle CC.
Settle B=5B = 5
From BB: DD becomes min(7,  5+6)=7\min(7, \; 5 + 6) = 7 (no change). Settle BB.
Settle D=7D = 7
From DD: EE becomes min(12,  7+2)=9\min(12, \; 7 + 2) = 9 (predecessor DD); F=7+7=14F = 7 + 7 = 14; G=7+10=17G = 7 + 10 = 17. Settle DD.
Settle E=9E = 9
From EE: FF becomes min(14,  9+3)=12\min(14, \; 9 + 3) = 12 (predecessor EE); GG becomes min(17,  9+4)=13\min(17, \; 9 + 4) = 13 (predecessor EE). Settle EE.
Finish
Settle F=12F = 12: GG becomes min(13,  12+2)=13\min(13, \; 12 + 2) = 13 (no change). Settle FF, then G=13G = 13.
Trace back
GG from EE, EE from DD, DD from CC, CC from AA: route AA-CC-DD-EE-GG.
Answer
cheapest route AA-CC-DD-EE-GG, total 4+3+2+4=134 + 3 + 2 + 4 = 13 dollars. (Check: AA-CC-DD-EE-FF-GG gives 4+3+2+3+2=144 + 3 + 2 + 3 + 2 = 14 dollars, more, so 1313 dollars is the minimum.)
ExamExplained