Kruskal's and Prim's Algorithms on a Network | AQA A Level Further Maths notes
Free preview: Kruskal's and Prim's Algorithms on a Network
Connecting Everything as Cheaply as Possible
Year 1 (AS) for OCR B (MEI). For the other boards, check your own specification for which parts are AS and which are A level.
Let's start with a real job. A company must connect seven buildings with cables. Each possible cable route has a cost. Every building must be connected (directly or through others), as cheaply as possible. Which cables should it lay?
The words we need
- A spanning tree of a connected graph is a subgraph that includes every vertex and is a tree (connected, no cycles).
- A minimum spanning tree (MST, also called a minimum connector) is a spanning tree with the smallest possible total weight.
- Why a tree? A cycle would mean one cable is not needed: you could remove it and everything stays connected, saving money.
- With n vertices, a spanning tree always has edges (you met this fact for trees).

Following the diagram
- The numbers are the costs (in thousands of pounds) of laying each cable.
- There are 7 buildings, so a spanning tree needs exactly 6 cables.
- Using every cable would cost 140. We want the cheapest 6 cables that still connect everything.
Could we just try every possible spanning tree? For this small network maybe, but big networks have millions of spanning trees. We need an algorithm. There are two famous ones, and both are greedy: at every step they grab the cheapest thing allowed. Amazingly, for this problem greedy always gives the best answer.
💡 In plain words
- Spanning tree: just enough edges to connect every vertex, with no wasted edge.
- Minimum spanning tree: the cheapest way of doing that.
✏️ YOUR TURN 1
Try this first:
(a) A network has 11 vertices. How many edges are in a spanning tree? (b) A spanning tree is chosen for the seven buildings, and then one more cable is added. Explain why the total can no longer be the minimum.
Answer:
- (a) edges.
- (b) A tree on 7 vertices already connects them all with 6 edges. A 7th edge joins two vertices that are already connected, so it makes a cycle. That cable is not needed, and removing it saves its cost (all costs are positive).
Kruskal's Algorithm: Cheapest Edges First
The recipe
- Sort the edges into ascending order of weight. Why: Kruskal looks at the cheapest edges first.
- Take the edges in that order. Add each edge to the tree unless it makes a cycle with edges already chosen; if it does, reject it. Why: an edge that makes a cycle joins two vertices that are already connected, so it is wasted money.
- Stop when edges have been chosen. Why: a spanning tree has exactly edges, so you are finished.
💡 In plain words
- Kruskal is greedy: always grab the cheapest edge left, unless it would be wasted (a cycle).
- The growing set of edges may be in separate pieces for a while. They join up by the end.
Sorted edges: EF 6, BC 7, DE 8, DF 9, AC 10, FG 11, BE 12, AB 13, DG 14, CE 15, BD 16, CF 19.
| Edge | Weight | Decision | Why |
|---|---|---|---|
| EF | 6 | add | cheapest edge |
| BC | 7 | add | no cycle |
| DE | 8 | add | no cycle |
| DF | 9 | reject | D–E–F–D would be a cycle |
| AC | 10 | add | no cycle |
| FG | 11 | add | no cycle |
| BE | 12 | add | joins piece {A, B, C} to piece {D, E, F, G} |

What the picture shows
- Kruskal has already chosen EF (6), BC (7) and DE (8), in green. The next cheapest edge is DF (9).
- Wrong: adding DF closes the shaded triangle D, E, F. A tree has no cycles, and the cable DF would be wasted money, because D and F are already connected.
- Right: ask "are D and F already joined by green edges?" Yes, through E. So reject DF and write it down as rejected.
- Move on to the next edge, AC (10). A and C are not yet connected, so add it.
Unlock the full note: start 7 days free.
Log in or subscribe to read the rest of this note. Members also get the AI tutor, practice quizzes, mock exams and flashcards for this topic.
All notes in Minimum Spanning Trees
- Kruskal's and Prim's Algorithms on a Network
- Prim's Algorithm on a Distance Matrix and Spanning Tree Problems
What's inside for this topic
2 teacher notes, 60 practice questions, 41 flashcards, 2 quizzes.
Get the full notes, every practice question, flashcards, quizzes and mock papers.
Next note: Prim's Algorithm on a Distance Matrix and Spanning Tree Problems
Kruskal's and Prim's Algorithms on a Network on other exam boards
All AQA A Level Further Maths topics · A Level Further Maths