Loading
A minimum spanning tree connects all n nodes with n − 1 edges of least total weight. Kruskal adds the cheapest edges that make no cycle; Prim grows one tree, always by its cheapest outgoing edge.
Edges: A–B 4, A–C 2, B–C 1, B–D 5, C–D 8, C–E 10, D–E 2, D–F 6, E–F 2. Find a minimum spanning tree by Kruskal’s algorithm.
Sort the edges by weight. Take each edge in turn unless it makes a cycle. Stop at n − 1 = 5 edges.
| Edge | Weight | Take or skip |
|---|---|---|
| B–C | 1 | take |
| A–C | 2 | take |
| D–E | 2 | take |
| E–F | 2 | take |
| A–B | 4 | skip (makes a cycle) |
| B–D | 5 | take |
The calculator below opens on this example.
Taking an edge that closes a loop.
Stopping too early or late.
Unsorted edges.
Thinking the MST gives shortest paths.
The graph must be connected and undirected.
Add this calculator to a new note, next to your own working. It stays live: change the numbers there any time.