Minimum Spanning Tree

Context: FIT2004_MOC · the cheapest way to connect every vertex — a Spanning Tree minimising , built greedily by Prim’s Algorithm (grow one tree) or Kruskal’s Greedy Algorithm (merge many trees) Parent Framework: Spanning Tree

Quick Revision

  • 🎯 Objective: undirected weighted ➔ acyclic subgraph touching every vertex with minimum total edge weight.
  • 📦 Core Components: Prim’s Algorithm ➔ , a Dijkstra variant growing from a root | Kruskal’s Greedy Algorithm ➔ , sort Union-Find (Disjoint Set).
  • ⚡ Key Constraint: the weight is unique, the tree is not — equal-weight edges give several MSTs of equal cost, so it is always an MST, never the MST.

📝 How It Works

1. The Three Words

  • Tree ➔ no cycle and undirected; equivalently the maximum edge set carrying no cycle.
  • Spanning ➔ contains every vertex of and only edges of (Subgraph); equivalently the minimum edge set that connects them ⟹ exactly edges.
  • Minimum ➔ minimises , not the edge count — every spanning tree already has edges, so only the weights discriminate.
  • Precondition ➔ connected and undirected; disconnected ⟹ a minimum spanning forest, one tree per component.

2. Not Unique, and Not a Shortest-Path Tree

  • Ties duplicate answers ➔ the lecture graph has and : two different edge sets, one optimum cost.
  • Optimal cost is unique ➔ so an exam answer is marked on and on the selection order, which is why both algorithms are examined as ordered traces.
  • MST shortest-path tree ➔ Dijkstra minimises accumulated from one source; MST minimises the total of the chosen edges and has no source. Swapping the relaxation formula is exactly the diff ➔ Prim’s Algorithm §2.
  • What MST paths DO minimise ➔ the largest single edge on the path (§4), not its total length.

3. Negative Weights Are Fine

  • Both algorithms survive ➔ Prim and Kruskal only ever compare edge weights against each other; nothing is accumulated, so the sign is irrelevant.
  • Contrast with Dijkstra ➔ Dijkstra sums weights into a distance, so one negative edge can lower an already-finalised estimate and break the greedy step. MST greed never finalises a distance.
  • The proofs do not spend non-negativity ➔ unlike Dijkstra’s contradiction argument, neither MST correctness proof uses anywhere.
  • Shift argument (a second proof) ➔ add a constant to every edge; each spanning tree gains exactly , so the ranking of trees is unchanged ⟹ the MST of the shifted non-negative graph is the MST of the original.
  • Negative cycles are harmless ➔ a cycle is never built in the first place; there is no “cheaper by looping” failure mode.

4. The Bottleneck Property (applied P4)

  • Bottleneck path ➔ an – path minimising the maximum edge weight on it, instead of the total.
  • Theorem ➔ every path inside an MST is a bottleneck path of .
  • Converse fails ➔ a bottleneck path need not lie in any MST (§Applied Exercise, counterexample).
  • Why it is the same greed ➔ Kruskal adds edges cheapest-first, so any pair of vertices is joined by the lightest heaviest-edge available — the bottleneck guarantee falls straight out of the cut logic.

5. Reverse-Delete: Kruskal Run Backwards (applied P5)

  • Algorithm ➔ sort descending, start with , and delete each edge in turn iff stays connected.
  • Invariant ➔ is always a superset of some MST (Kruskal’s is ” is always a subset of some MST”).
  • Termination shape ➔ output is connected (never disconnects) and acyclic (any edge in a cycle could have been removed) ⟹ a spanning tree; superset equal edge counts ⟹ is an MST.
  • Transfer (LO1) ➔ the same greedy correctness template runs in either direction; what changes is subset ➔ superset and cheapest safe addition ➔ dearest safe deletion.

6. Maximum Spanning Tree — Invert the Comparison, Not the Algorithm

  • Same object, opposite objective ➔ a MaxST maximises over the same edges; spanning and acyclicity are untouched.
  • Prim ➔ swap the min-Heap for a max-heap and relax on .
  • Kruskal ➔ sort the edges descending; the find/union test does not change.
  • Either, without editing the code ➔ negate every weight and run the stock minimum version — the smallest negative is the largest positive — then negate the total back.
  • Why it is sound ➔ both correctness proofs only ever compare two weights (§3), and negation reverses every comparison consistently.

⚖️ Core Decision Matrix

NeedReach forWhyCost
MST, dense graph, adjacency matrixPrim’s Algorithmno edge sort; grows from one root, serves, with an array-based serve
MST, sparse graph, edge list givenKruskal’s Greedy Algorithmthe sort is the whole cost
MST when edges arrive already sortedKruskal’s Greedy Algorithmsort is free ⟹ near-linear with Union-Find (Disjoint Set)
Minimise the largest edge on an – pathany MST, then walk itMST paths are bottleneck paths (§4)
Minimise accumulated distance from a sourceDijkstra’s Algorithmdifferent objective entirely
Graph is directedneitherMST is defined on undirected graphs only—

When It Flips: density, not correctness, chooses the algorithm — both are and both accept negative weights. Kruskal wins when the edges are already a sorted list; Prim wins when the graph is dense and you never want to materialise all edges.

📊 Exam Execution Trace & Applied Exercises

Applied Exercise — prove MST paths are bottleneck paths (P4b)

Problem: weighted connected undirected, an MST, . Show the unique -path from to is a bottleneck path.

Final Extracted Output: a spanning tree strictly lighter than — contradiction, so is a bottleneck path. The reusable move is the cut-and-swap: delete a tree edge, cross the induced cut with something cheaper, rebuild.

Applied Exercise — the converse fails (P4c)

Problem: exhibit a bottleneck path that lies in no MST. Graph: , , , . Final Extracted Output: is a bottleneck path (max edge , unavoidable since ‘s only edge is ) but the MST is of weight , and costs ⟹ edge is in no MST. Bottleneck-optimal MST-member.

⚠️ Common Mistakes

  • 💡 “The MST” ➔ say a minimum spanning tree; only the cost is unique. On a tie the marker expects your tie-break rule stated, not a claim of uniqueness.
  • 💡 Refusing negative weights ➔ the non-negativity precondition belongs to Dijkstra, not to MST. Quoting it here is a straight mark loss on the highest-frequency short-answer question of the week.
  • 💡 Reading an MST as a shortest-path tree ➔ the – path in an MST minimises its heaviest edge, and can be arbitrarily longer in total than the true shortest path.

🧠 Active Recall