A levels Further Mathematics · Decision mathematics
Minimum spanning trees
1Spanning trees
A spanning tree of a connected graph is a tree that includes every vertex. It has $n - 1$ edges for $n$ vertices.
A minimum spanning tree (MST) is a spanning tree with the smallest total weight. It solves problems such as connecting towns with the least cable or pipe.
Counting edges
- A network has 6 vertices.
- Any spanning tree has exactly $6 - 1 = 5$ edges.
Check yourself
How many edges does a spanning tree of a network with 9 vertices have?
Show the answer
8
n − 1.
2Kruskal's algorithm
Kruskal's algorithm:
- List the edges in order of weight, smallest first.
- Take each edge in turn. Add it unless it would make a cycle; if it would, reject it.
- Stop when $n - 1$ edges have been chosen.
Kruskal on the network
- Edges in order: BC 2, AC 3, DE 3, AB 4, DF 4, BD 5, CE 6, EF 7, CD 8.
- Add BC, AC, DE.
- Reject AB (it would make the cycle A–B–C).
- Add DF, then BD. That is 5 edges, so stop.
- MST: BC, AC, DE, DF, BD, with total weight $2 + 3 + 3 + 4 + 5 = 17$.
Kruskal's minimum spanning tree in green: BC, AC, DE, DF, BD. AB (4) was rejected because it would close the cycle A–B–C.
Check yourself
In Kruskal's algorithm, when is an edge rejected?
Show the answer
When it would form a cycle
A tree has no cycles.
3Prim's algorithm
Prim's algorithm grows one tree from a starting vertex:
- Choose any starting vertex.
- Add the shortest edge joining a vertex in the tree to a vertex not yet in the tree.
- Repeat until every vertex is included.
Prim from A
- Start at A. Shortest edge out: AC 3.
- From {A, C}: shortest edge to a new vertex is CB 2.
- From {A, B, C}: shortest is BD 5 (AB would not add a new vertex).
- From {A, B, C, D}: DE 3, then DF 4.
- Order: AC, CB, BD, DE, DF. Total 17, the same as Kruskal.
Prim's algorithm never needs to check for cycles, because each new edge always brings in a new vertex.
Check yourself
Why does Prim's algorithm never need to check for cycles?
Show the answer
Each edge added joins the tree to a new vertex
A new vertex cannot close a cycle.
4Prim's algorithm on a distance matrix
Prim's algorithm can be carried out directly on a distance matrix, which is how a computer would do it.
- Choose a starting vertex; cross out its row and number its column.
- Look down all numbered columns for the smallest value not crossed out.
- That value's row gives the new vertex: cross out its row and number its column.
- Repeat until all rows are crossed out.
A distance matrix
- Vertices P, Q, R, S with PQ 5, PR 8, PS 3, QR 4, QS 7, RS 6. Start at P.
- Smallest in column P: 3 (PS). Add S.
- Smallest in columns P and S (rows Q, R): 5 (PQ). Add Q.
- Smallest in columns P, S, Q (row R): 4 (QR). Add R.
- MST: PS, PQ, QR, total 12.
Check yourself
On a distance matrix, which rows are crossed out in Prim's algorithm?
Show the answer
The rows of vertices already in the tree
So you only look at edges to new vertices.
5Comparing the two algorithms
Both Kruskal and Prim always give a minimum spanning tree, but they work differently:
- Kruskal sorts all edges first and may build several separate pieces that later join up. It needs a cycle check.
- Prim grows a single tree and suits a distance matrix.
If several edges have equal weights, there may be more than one MST, but they all have the same total weight.
Ties
- If two edges of weight 4 could both be chosen next in Kruskal, either may be added first.
- The final total weight is the same, though the tree may differ.
Check yourself
Can a network have more than one minimum spanning tree?
Show the answer
Yes, if some edges have equal weights
The total weight is still the same.
6Using minimum spanning trees
Typical uses: laying cables, pipes or roads to connect every location at least cost.
Adding a condition
- In the network, suppose edge CE must be included (for example, a road already planned).
- Include CE first, then continue Kruskal: BC, AC, DE, then AB (rejected: cycle), DF, then BD would make the cycle B–D–E–C–B, so it is rejected.
- Tree: CE, BC, AC, DE, DF, total $6 + 2 + 3 + 3 + 4 = 18$, which is 1 more than the MST.
An MST connects everything, but it does not give the shortest route between two particular vertices: that is a shortest path problem.
Check yourself
Does a minimum spanning tree give the shortest route between two given vertices?
Show the answer
Not necessarily
Use Dijkstra's algorithm for that.
Now test yourself
This lesson has a 8-question quiz and 5 exam-style questions with mark schemes in Impera. Free, with your progress saved.
Practise in Impera