Minimum spanning treesEdexcel International A Level Maths: Revision notes
Section 1
Trees and the minimum connector problem
A tree is a connected network with no cycles. A spanning tree of a network is a tree that includes every vertex, using some of the original arcs. A network with vertices has a spanning tree with exactly arcs. If you add one more arc you create a cycle, and if you take one away a vertex is cut off. The minimum spanning tree (MST), also called the minimum connector, is the spanning tree with the smallest total weight. It solves problems such as connecting every site to a water, cable or road network at least cost. A network can have more than one MST when arcs have equal weights.
Check your answer has exactly arcs and no cycle. Both checks take seconds.
Section 2
Kruskal's algorithm
Kruskal's algorithm builds the MST by choosing arcs.
- Sort the arcs into increasing order of weight.
- Select the smallest arc.
- Select the next smallest arc, rejecting it if it would form a cycle with arcs already chosen.
- Repeat step 3 until arcs have been selected. Example: arcs , , , , . Accept , , , ; reject because and are already joined through . Weight . Kruskal's algorithm works on the list of arcs, so it does not need a starting vertex. In the exam show the order in which you consider the arcs and write which are rejected.
Rejecting an arc just because it joins two vertices that already have arcs. Reject it only if the two ends are already connected to each other.
Section 3
Prim's algorithm on a network
Prim's algorithm grows a single tree from a starting vertex.
- Choose any vertex to start.
- Select the smallest-weight arc joining a vertex in the tree to a vertex not yet in the tree.
- Repeat until every vertex is in the tree. Example: start at with arcs and : choose . From , arcs to new vertices are , , , : choose , then , then . The weight is again. The tree is built outwards, so the arcs may be chosen in a different order from Kruskal's, but the total weight of the MST is the same. Prim's algorithm is easier to apply from a table or matrix because you never need to check for cycles: you only ever add a new vertex.
Choosing the smallest arc anywhere in the network. Prim's arc must join the current tree to a vertex outside it.
Section 4
Prim's algorithm on a matrix
A network can be shown as a distance matrix: rows and columns are labelled with the vertices, and the entry in row and column is the weight of arc . A dash means there is no arc. The matrix is symmetrical about the leading diagonal, so each arc appears twice. To apply Prim's algorithm to the matrix:
- Choose a starting vertex. Label its column 1 and delete (cross out) its row.
- Look at the labelled columns, and in them circle the smallest entry in a row that is not yet deleted.
- The circled entry gives the next arc. Label the column of the new vertex with the next number, and delete its row.
- Repeat until all rows are deleted. The numbers 1, 2, 3, ... give the order in which the vertices are added, and the circled entries are the arcs of the MST.
Ignore entries in columns that are already labelled, otherwise you will pick an arc that makes a cycle.
Section 5
Drawing a network from a matrix, and writing a matrix
To draw a network from a matrix, mark each vertex, then for each non-blank entry in the upper triangle draw one arc between those vertices and write the weight on it. Only use half of the matrix, otherwise every arc is drawn twice. To write the matrix for a network, make a square table, put each arc weight in the cell for each end (once in each triangle), and put a dash for any pair with no arc. Example: the matrix with row = , 12, 9, 15, gives arcs , and , with no arc . The number of arcs equals half the number of non-blank entries. Matrix manipulation is not needed.
Counting every non-blank entry as a separate arc. Each arc appears twice in the matrix.
Section 6
Exam skills and checks
Always show the order in which arcs are considered or added. Marks are given for the method as well as the final weight. If two arcs have equal weight, either can be chosen, and the MST may differ but its weight will not. If an arc is forced into the tree, include it first, then continue the algorithm. The cost is at least the MST weight. When a new vertex is added, find the new MST by repeating the algorithm. Some old arcs may drop out when the new arcs offer cheaper connections.
Count the arcs at the end: arcs for vertices.
That's the notes covered.
Carry on to the next subtopic.
Exam questions on Minimum spanning trees
- A network has five vertices , , , and . The arcs and their weights are , , , , , and .Use Kruskal's algorithm to find a minimum spanning tree for the network. List the arcs in the order in which you consider them, stating whether each is accepted or rejected, and find the total weight of the tree.2 marks
- A network has five vertices , , , and , shown by the following distance matrix. A dash means there is no arc. The rows, in order, are:
: , 12, 9, 15,
: 12, , 8, , 14
: 9, 8, , 11, 10
: 15, , 11, , 6
: , 14, 10, 6,
The columns are in the same order , , , , .Starting at , use Prim's algorithm to find a minimum spanning tree. State the order in which the arcs are added and the total weight of the tree.2 marks
- A water company must connect six villages to with pipes. The possible pipes and their costs, in thousands of pounds, are , , , , , , , and . Every village must be connected to every other village, directly or through other villages, at minimum total cost.Use Kruskal's algorithm to find a minimum spanning tree, showing the order in which you consider the arcs, and state the minimum cost.3 marks
Written by the Exaim team, led by Shaun Daswani (Head of Upper Secondary, Improve ME Institute; MSc Financial Mathematics, Imperial College London; BSc, UCL) and Jason Daswani (operational lead, Improve ME Institute; LSE).