All revision notes topics

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 nn nodes has exactly n−1n-1 arcs. Typical uses are laying cable, pipes or roads so that every site is connected using the least total length or cost.

Key termsnodearcweightspanning treeminimum spanning tree
Common mistake

Counting the arcs of the whole network instead of n−1n-1 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:

  1. List the arcs in ascending order of weight.
  2. Add the next arc to the tree unless it would form a cycle with arcs already chosen.
  3. Stop when n−1n-1 arcs have been chosen. Example: arcs EFEF 2, DEDE 3, BCBC 4, CDCD 5, ABAB 6 are accepted; CECE 7 is rejected because CC–DD–EE already connects CC and EE. The MST has weight 2+3+4+5+6=202+3+4+5+6=20.
Key termscycleKruskal's algorithm
Common mistake

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:

  1. Choose any starting node.
  2. Add the lightest arc that joins a node in the tree to a node not yet in it.
  3. Repeat until every node is in the tree. Starting at PP with PQPQ 12, PRPR 8, PTPT 9, QRQR 10, QSQS 7, RSRS 11, RTRT 6 and others heavier, the arcs added are PRPR 8, RTRT 6, QRQR 10, QSQS 7, total 31. Prim's tree is always connected as it grows, whereas Kruskal's may have separate pieces until the end.
Key termsPrim's algorithm
Exam tip

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 AA; 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.

Key termsdistance matrix
Common mistake

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.

Key termsminimum connector
Exam tip

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

  1. A network has six nodes AA to FF. The arcs and their weights are ABAB 6, ACAC 9, BCBC 4, BDBD 8, CDCD 5, CECE 7, DEDE 3, DFDF 10 and EFEF 2.
    Explain why Kruskal's algorithm rejects arc CECE.2 marks
  2. Five villages P,Q,R,S,TP,Q,R,S,T are to be linked by cables. The possible links and their costs, in hundreds of pounds, are PQPQ 12, PRPR 8, PSPS 15, PTPT 9, QRQR 10, QSQS 7, QTQT 14, RSRS 11, RTRT 6 and STST 13.
    Explain why Prim's algorithm starting at PP does not select arc QSQS, with weight 7, until the last step, even though it is lighter than arc PRPR.2 marks
  3. Five towns AA to EE are to be connected by cable laid along direct links. The distances in km between the towns, with rows and columns in the order A,B,C,D,EA,B,C,D,E, are given by (05948506739602104720118310110)\begin{pmatrix} 0&5&9&4&8 \\ 5&0&6&7&3 \\ 9&6&0&2&10 \\ 4&7&2&0&11 \\ 8&3&10&11&0 \end{pmatrix}. The cable is to have the least possible total length.
    Use Prim's algorithm, starting at AA, to find a minimum spanning tree. State the order in which the arcs are added and the total length.3 marks
See the full worksheet

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).