Minimal Spanning Trees and Connector Problems
Every question with a fully worked solution.
- Minimal Spanning Trees and Connector Problems - Video - Minimum Spanning Trees 1 Watch
- Minimal Spanning Trees and Connector Problems - Video - Minimum Spanning Trees 2 Watch
- Minimal Spanning Trees and Connector Problems - Video - Minimum Spanning Trees 3 Watch
- Minimal Spanning Trees and Connector Problems - Video - Minimum Spanning Trees 4 Watch
- Minimal Spanning Trees and Connector Problems - Video - Minimum Spanning Trees 5 Watch
- Minimal Spanning Trees and Connector Problems - Video - Minimum Spanning Trees 6 Watch
- Minimal Spanning Trees and Connector Problems - Video - Minimum Spanning Trees 7 Watch
- Minimal Spanning Trees and Connector Problems - Video - Connector Problems Watch
Theory
A minimum spanning tree joins every vertex of a weighted network at the least total length or cost. This Year 11 Mathematics Standard page shows how to find one with Kruskal's algorithm and Prim's algorithm, from a diagram, a list or a table, and how to solve connector problems such as laying cable or pipes, including costs and edges that must be included.
A connector problem asks you to join every place in a network as cheaply as possible: laying fibre cable between towns, power to buildings or water pipes to farms. You do not need every possible link, only enough to connect every place, with no wasted loops.
A spanning tree is a tree that includes every vertex of the network: it is connected and has no closed loops (cycles). A spanning tree for a network with \(n\) vertices always has \(n-1\) edges. The minimum spanning tree is the spanning tree with the smallest total weight (length, time or cost).
Two step-by-step methods find it. Kruskal's algorithm takes the edges from shortest to longest, skipping any edge that would make a closed loop. Prim's algorithm starts at one vertex and grows a single tree, each time adding the cheapest edge from the tree to a new vertex. Both give the same total weight.
The weights can also be given in a table. The number in row \(A\), column \(B\) is the weight of edge \(AB\), and a dash means there is no direct link. Each edge appears twice (row \(A\) column \(B\), and row \(B\) column \(A\)), so use it only once.
For a network with \(n\) vertices:
When the weights are lengths and you are given a price per metre or per kilometre:
| Algorithm | Start | Each step |
|---|---|---|
| Kruskal's | the shortest edge in the network | add the next shortest edge, unless it makes a closed loop |
| Prim's | the vertex you are told to start at | add the cheapest edge joining the tree to a vertex not yet in the tree |
Kruskal's algorithm
- List the edges from shortest to longest.
- Add the shortest edge, then the next shortest, writing “add” beside each one.
- Skip any edge whose two ends are already joined by edges you have added: it would make a closed loop.
- Stop when you have \(n-1\) edges (every vertex is joined), then add up the weights.
Prim's algorithm
- Start at the vertex you are given.
- List every edge from a vertex already in the tree to a vertex not yet in the tree, and add the cheapest.
- Repeat until every vertex is in the tree, then add up the weights.
Special cases
- An edge that must be included (for example, a pipe that is already built): put it in first, then use Kruskal's algorithm on the other edges.
- Is a given tree the minimum? Look for an edge that is not used. If adding it makes a loop that contains a longer edge, swap them: the tree was not the minimum.
- Cost: multiply the total length by the cost per metre or kilometre.
Take the edges from shortest to longest, skipping any that would make a closed loop:
| \(BD\) | \(=\) | \(3\quad\text{add}\) |
| \(AC\) | \(=\) | \(4\quad\text{add}\) |
| \(CD\) | \(=\) | \(5\quad\text{add}\) |
| \(BC\) | \(=\) | \(6\quad\text{skip (loop B-C-D)}\) |
| \(AB\) | \(=\) | \(7\quad\text{skip (loop)}\) |
| \(CE\) | \(=\) | \(8\quad\text{add}\) |
There are 5 vertices, so the tree needs \(5-1=4\) edges. It now has 4, so \(DE=9\) is not needed.
| \(\text{Total}\) | \(=\) | \(3+4+5+8\) |
| \(=\) | \(20\) |
The minimum spanning tree has length \(\mathbf{20}\).
| \(P\) | \(Q\) | \(R\) | \(S\) | \(T\) | |
|---|---|---|---|---|---|
| \(P\) | – | 12 | 7 | – | 10 |
| \(Q\) | 12 | – | 9 | 6 | – |
| \(R\) | 7 | 9 | – | 11 | – |
| \(S\) | – | 6 | 11 | – | 8 |
| \(T\) | 10 | – | – | 8 | – |
Grow the tree from \(P\), each time adding the cheapest edge from the tree to a new farm.
Step 1: edges from \(P\): \(PQ=12,\ PR=7,\ PT=10\). Add \(PR=7\).
Step 2: edges from \(\{P,R\}\): \(PQ=12,\ PT=10,\ RQ=9,\ RS=11\). Add \(QR=9\).
Step 3: edges from \(\{P,Q,R\}\): \(PT=10,\ QS=6,\ RS=11\). Add \(QS=6\).
Step 4: edges from \(\{P,Q,R,S\}\): \(PT=10,\ ST=8\). Add \(ST=8\).
All 5 farms are joined with \(5-1=4\) pipes.
| \(\text{Total}\) | \(=\) | \(7+9+6+8\) |
| \(=\) | \(30\) |
The pipes are chosen in the order \(PR,\ QR,\ QS,\ ST\), and the minimum cost is \(30\) thousand dollars, which is \(\mathbf{\$30\,000}\).
\(AB=40,\ AC=25,\ BC=30,\ BD=35,\ CD=45,\)
\(CE=50,\ DE=20,\ DF=30,\ EF=25\)
Every building must be connected. Cable costs \(\$18\) per metre to lay. Find the minimum cost.
Use Kruskal's algorithm. \(AC\) and \(EF\) are both 25, and \(BC\) and \(DF\) are both 30: take either one first.
| \(DE\) | \(=\) | \(20\quad\text{add}\) |
| \(AC\) | \(=\) | \(25\quad\text{add}\) |
| \(EF\) | \(=\) | \(25\quad\text{add}\) |
| \(BC\) | \(=\) | \(30\quad\text{add}\) |
| \(DF\) | \(=\) | \(30\quad\text{skip (loop D-E-F)}\) |
| \(BD\) | \(=\) | \(35\quad\text{add}\) |
That is \(6-1=5\) edges, so all 6 buildings are joined.
| \(\text{Total}\) | \(=\) | \(20+25+25+30+35\) |
| \(=\) | \(135\text{ m}\) | |
| \(\text{Cost}\) | \(=\) | \(135\times 18\) |
| \(=\) | \(\$2430\) |
The minimum cost is \(\mathbf{\$2430}\).
(ii) The pipeline \(AD\) has already been built and must be part of the network. Find the minimum total length of pipeline, including \(AD\).
(i) The suggested tree has length \(6+5+7+3=21\) km. The pipeline \(BD=4\) is not used. Adding it makes the loop \(B\)-\(C\)-\(D\)-\(B\), which contains \(CD=7\). Swapping \(CD=7\) for \(BD=4\) still joins every town and is \(3\) km shorter (\(18\) km). So the suggested tree is not the minimum: \(D\) should join to \(B\) (weight 4), not to \(C\) (weight 7).
(ii) Start with \(AD=8\), then use Kruskal's algorithm on the other edges:
| \(DE\) | \(=\) | \(3\quad\text{add}\) |
| \(BD\) | \(=\) | \(4\quad\text{add}\) |
| \(BC\) | \(=\) | \(5\quad\text{add}\) |
| \(AB\) | \(=\) | \(6\quad\text{skip (loop A-B-D)}\) |
All 5 towns are now joined with 4 edges.
| \(\text{Total}\) | \(=\) | \(8+3+4+5\) |
| \(=\) | \(20\text{ km}\) |
The minimum total length is \(\mathbf{20}\) km (2 km more than the minimum spanning tree, which uses \(AB=6\) instead of \(AD=8\)).
Common pitfalls
Frequently asked questions
What is a minimum spanning tree?
It is a set of edges that joins every vertex of a weighted network with no closed loops, and has the smallest possible total weight.
How many edges does a spanning tree have?
A spanning tree for a network with \(n\) vertices has \(n-1\) edges. For example, 10 towns need 9 links.
What is the difference between Kruskal's and Prim's algorithm?
Kruskal's algorithm takes edges from shortest to longest anywhere in the network, skipping any that make a loop. Prim's algorithm starts at one vertex and grows one tree, each time adding the cheapest edge to a new vertex. Both give the same total.
What happens if two edges have the same weight?
Take either one first. The tree you end up with may be different, but its total weight is the same.
What is a connector problem?
A practical problem where every place must be connected at the least total length or cost, such as laying cable, pipes or roads. It is solved by finding a minimum spanning tree.