Further Maths Help.co.uk

Topics

Shortest paths with Dijkstra’s algorithm

Dijkstra’s algorithm settles vertices in order of their current distance from the start.

Start with distance zero at the source and infinity elsewhere. Select the unsettled vertex with least tentative distance, settle it and update distances to its neighbours. Store predecessors to recover an actual route.

The usual algorithm requires nonnegative edge weights. A minimum spanning tree solves a different problem: connecting all vertices with minimum total weight. Record both the route and its total distance when a shortest-path question asks for them.

Worked example

Edges AB = 4, AC = 1 and CB = 2. Find the shortest route from A to B.

  1. From A, tentative distances are B = 4 and C = 1.
  2. Settle C, then update B to 1 + 2 = 3.
  3. Settle B and recover its predecessor C.

Answer: A → C → B, distance 3

A permanent label needs nonnegative edge weights

Dijkstra’s algorithm makes the smallest temporary label permanent, then relaxes every edge from that vertex. Record a predecessor whenever a route improves. The label gives the distance; the predecessors recover the route. Its usual correctness argument requires nonnegative weights. A shortest route and a minimum spanning tree solve different problems.

An indirect route improves a label

Take undirected edges AB=4, AC=1, CB=2 and BD=1. From A, make C permanent at 1, improve B from 4 to 3 via C, then reach D at 4 via B. The route is A–C–B–D.

A tied distance

Add CD=3. D can be reached by A–C–D in the same total 4. One predecessor chain gives one shortest route; a tie means it need not be unique.

A mistake worth checking

Do not make a label permanent just because it was discovered first. Choose the smallest current temporary distance.

Does a negative edge always create a negative cycle?

No in a directed graph. However, it can invalidate Dijkstra’s permanent-label argument even without a negative cycle. In an undirected model, traversing a negative edge back and forth creates a negative closed walk.

Try this before opening the working

Why might the minimum spanning tree fail to preserve the shortest A-to-B route?

Compare your reasoning

It minimises total connector weight across all vertices. Removing a heavier edge can reduce construction cost while lengthening a particular pairwise route. Check the two objectives separately.

Choose a longer question · Check a misconception

Practise shortest paths with dijkstra’s algorithm

Course mapping

These specification references show where the topic occurs. The questions cover only some parts of each topic.

Next practice: Proof by induction.