Small Group Tutorials

Here to help students catch up, keep up, and move ahead. Book a consultation here.

How to Learn Minimum Spanning Trees: Cut Property, Kruskal, Prim and Proof of Choice

Wait, What?

The cheapest edge in the whole graph is not enough to explain why an entire cheapest network is correct.

Minimum spanning tree algorithms are often taught as two procedures to memorise: Kruskal sorts edges; Prim grows a tree. That misses the deeper idea. Both algorithms are safe because they repeatedly choose an edge justified by a structural property of cuts.

Quick Answer

A minimum spanning tree (MST) connects every vertex of a connected weighted undirected graph with no cycles and minimum possible total edge weight. Learn MSTs in this order: understand what a spanning tree is → learn the cut property → use that property to justify greedy choices → trace Kruskal and Prim → connect each algorithm to its supporting data structure → analyse complexity, equal-weight cases and disconnected graphs.

Stage 1 — Separate “Tree”, “Spanning” and “Minimum”

  • A tree is connected and acyclic.
  • A spanning tree includes every vertex of the original connected graph.
  • A minimum spanning tree is a spanning tree whose total edge weight is as small as possible.

A spanning tree on V vertices has V − 1 edges. That count is a useful check, but not a proof of minimum weight. Learners should first draw several different spanning trees for the same small graph and total their weights. The problem only becomes meaningful after seeing that many legal trees may exist.

Stage 2 — Learn the Cut Property

A cut divides the vertices into two sets. Any edge with endpoints on opposite sides crosses the cut. The core safe-choice idea is: under the standard conditions, a minimum-weight crossing edge for a cut compatible with the partial solution can be chosen as part of an MST.

This is what turns greedy choice from a guess into an argument. Do not let learners memorise the words “cut property” without using them. Give a graph, draw a cut, list crossing edges, identify the lightest one, then ask why replacing a heavier crossing edge in another spanning tree cannot make the result worse.

Stage 3 — Kruskal as Global Edge Selection

Kruskal’s algorithm considers edges from lightest to heaviest. Add an edge if it connects two components that are currently separate; skip it if it would create a cycle. Continue until the spanning tree is complete.

sort edges by weight
for each edge (u, v) in that order:
    if u and v are in different components:
        add edge
        merge the components

This is where the existing Union-Find learning lane becomes useful. Union-Find does not explain why Kruskal is correct; it efficiently answers the implementation question “Are these endpoints already connected?” and performs the merge when they are not.

Stage 4 — Prim as a Growing Frontier

Prim’s algorithm starts from one vertex and grows a single tree. At each step, choose a minimum-weight edge crossing from the vertices already in the tree to a vertex outside it. The cut is now visible: tree vertices on one side, non-tree vertices on the other.

A priority queue helps find the next cheapest eligible crossing edge efficiently. Lazy and eager implementations differ in what they keep in the queue and when stale edges are discarded or replaced.

Kruskal and Prim: Same Goal, Different State

  • Kruskal: maintains a forest of components and considers edges globally by weight.
  • Prim: maintains one growing tree and considers the frontier leaving that tree.
  • Shared reasoning: each accepted edge is supported by a safe greedy choice related to a cut.

Common Failure States

  • “Always take the cheapest edge”: without cycle or cut conditions, this rule can fail.
  • Shortest-path confusion: an MST minimises total tree weight, not the distance from a source to every vertex.
  • Directed-graph confusion: the standard MST problem is defined for undirected weighted graphs.
  • Negative weights panic: negative edge weights do not break MST algorithms; the structural problem remains meaningful.
  • Equal weights = failure: equal weights can produce multiple MSTs. Non-uniqueness is not incorrectness.
  • Disconnected graph ignored: there is no single spanning tree across disconnected components; algorithms may instead produce a minimum spanning forest.

A Strong Practice Ladder

  • Draw three spanning trees and compare weights.
  • Mark a cut and identify its crossing edges.
  • Explain one safe edge using the cut property.
  • Trace Kruskal by hand, recording Union-Find components.
  • Trace Prim, recording the tree frontier and priority queue.
  • Construct a graph with multiple valid MSTs.
  • Construct a graph where shortest paths and the MST visibly differ.
  • Implement both algorithms and compare behaviour on sparse and dense inputs.

Professional Extension — The Model Must Match the Real Network

MSTs model “connect everything as cheaply as possible” only when edge weights capture the relevant cost and when a tree is an acceptable final topology. Real networks may require redundancy, capacity, reliability, geographic constraints, degree limits or multiple objectives. A mathematically optimal MST can therefore be an incomplete engineering solution.

Professional judgement begins by distinguishing the algorithmic problem from the real-world system. First ask whether the desired object really is a spanning tree. Then choose the algorithm and implementation that match graph size, density, update pattern and available data structures.

How Do We Know?

Princeton’s Algorithms materials make the cut property central to MST reasoning and present Prim and Kruskal as greedy special cases. Their reference implementations document Kruskal with Union-Find and Prim with indexed priority queues, including standard complexity bounds and the fact that equal, zero or negative weights can be handled.

Learning Evidence and Scaffold Fade

For novices, the proof idea should be made visible before implementation details accumulate. Research on programming instruction supports worked examples and subgoal labels for reducing the search burden early in learning, while scaffold-fading literature emphasizes transferring responsibility as competence grows. Here the fade is: labelled cuts → partially labelled cuts → independent safe-edge justification → algorithm trace → implementation → comparison under new graph conditions.

Connections in the Learning Hall

Use Greedy Algorithms for the general local-choice reasoning. The current Union-Find and Heaps/Priority Queues drafts provide the implementation machinery used by Kruskal and Prim. This article owns the MST problem, its cut-based proof idea, and the comparison of the two algorithms.

MST rule: do not memorise Kruskal or Prim as edge-picking recipes; learn which cut makes the next greedy choice safe.