Spanning trees and network optimisationAQA A-Level Further Maths: Revision notes
Section 1
The language of networks
A network is a graph in which every edge has a number, its weight, such as a distance, cost or time. The points are nodes (vertices) and the lines joining them are arcs (edges). A tree is a connected network with no cycles. A spanning tree is a tree that contains every node of the network, and a minimum spanning tree (MST) is a spanning tree of least total weight. A spanning tree of a network with nodes has exactly arcs. Typical uses are laying cable, pipes or roads so that every site is connected using the least total length or cost.
Counting the arcs of the whole network instead of when asked how many arcs a spanning tree has.
Section 2
Kruskal's algorithm
Kruskal's algorithm builds an MST by arcs, working across the whole network:
- List the arcs in ascending order of weight.
- Add the next arc to the tree unless it would form a cycle with arcs already chosen.
- Stop when arcs have been chosen. Example: arcs 2, 3, 4, 5, 6 are accepted; 7 is rejected because –– already connects and . The MST has weight .
Rejecting an arc just because both its nodes are in the tree: it is only rejected if they are already connected, that is if it would make a cycle. Two separate pieces of tree may still be joined.
Section 3
Prim's algorithm on a network
Prim's algorithm grows a single tree from a starting node:
- Choose any starting node.
- Add the lightest arc that joins a node in the tree to a node not yet in it.
- Repeat until every node is in the tree. Starting at with 12, 8, 9, 10, 7, 11, 6 and others heavier, the arcs added are 8, 6, 10, 7, total 31. Prim's tree is always connected as it grows, whereas Kruskal's may have separate pieces until the end.
State each arc as you add it, with its weight, and give the order: the order of choice is part of the answer.
Section 4
Prim's algorithm on a distance matrix
When the network is given as a distance matrix (rows and columns for nodes, the entry being the arc weight), Prim's algorithm works directly on it. Keep a list of nodes in the tree. At each step look at the columns (or rows) of the tree nodes, restricted to the rows of nodes not yet in the tree, and choose the smallest entry. That entry is the next arc. Add its node to the tree and repeat. Matrix method: start at ; cross out the row of each node as it joins the tree; circle the smallest uncrossed entry in the columns of tree nodes. The circled entries are the weights of the MST arcs.
Choosing the smallest entry in the whole matrix at every step. That is Kruskal's idea; Prim's must pick from arcs that leave the tree.
Section 5
Choosing and applying the methods
Both algorithms give a minimum spanning tree with the same total weight. If arcs have equal weights the MST may not be unique, but its weight is. Kruskal's algorithm needs the arcs sorted and a cycle check; Prim's needs no cycle check and suits matrices. If an arc becomes unavailable (a road closed), delete it and apply the algorithm again: the new MST is never lighter than the old. If it was in the original tree, the weight rises (or at best stays the same). An MST connects all the nodes using the least total weight. It does not give the shortest route between two particular nodes: in a network the direct arc between two nodes may be far shorter than the path through the tree.
Always finish with the total weight of the tree and the list of arcs used, with units.
That's the notes covered.
Carry on to the next subtopic.
Exam questions on Spanning trees and network optimisation
- A network has six nodes to . The arcs and their weights are 6, 9, 4, 8, 5, 7, 3, 10 and 2.Explain why Kruskal's algorithm rejects arc .2 marks
- Five villages are to be linked by cables. The possible links and their costs, in hundreds of pounds, are 12, 8, 15, 9, 10, 7, 14, 11, 6 and 13.Explain why Prim's algorithm starting at does not select arc , with weight 7, until the last step, even though it is lighter than arc .2 marks
- Five towns to are to be connected by cable laid along direct links. The distances in km between the towns, with rows and columns in the order , are given by . The cable is to have the least possible total length.Use Prim's algorithm, starting at , to find a minimum spanning tree. State the order in which the arcs are added and the total length.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).