BITS Pilani
CS F364: Design and Analysis of Algorithms

Minimum Spanning Trees

Lecture 15 |2026-06-09

Minimum Spanning Tree (MST)

  • Minimum Spanning Tree (MST)
  • Applications of MST
  • Cuts and the Cut Property
  • The Cycle Property
  • Union-Find Data Structure
  • Correctness of Kruskal’s Algorithm
  • Summary

What is a Spanning Tree?

A spanning tree of a connected graph G = (V, E) is a subgraph T \subseteq G such that:

  • Spanning: T includes all |V| vertices of G.
  • Tree: T is connected and acyclic.

Key facts: - Every spanning tree has exactly |V|-1 edges. - There is exactly one path between any two vertices in T. - A connected graph can have many different spanning trees.

Spanning Tree — Properties

  • A tree is the minimally connected subgraph — removing any edge disconnects it.
  • A tree is the maximally acyclic subgraph — adding any edge creates a cycle.
  • Every spanning tree of a graph on n vertices has exactly n-1 edges — no more, no fewer.

\text{connected} + \text{acyclic} + |V|-1 \text{ edges} \;\Longleftrightarrow\; \text{spanning tree}

Any two of these three properties implies the third.

Minimum Spanning Tree (MST)

Given a connected graph G=(V, E) with real valued edge weights c_e, an MST is a spanning tree T\subseteq E whose sum of edge weights is minimized.

  • T must be a spanning tree (connected, acyclic, all V vertices).
  • Among all spanning trees, T has the minimum total weight.

Why MST?

  • Foundational problem — one of the oldest and most well-studied in graph theory (Boruvka, 1926)

  • Greedy paradigm — all three classical algorithms (Kruskal’s, Prim’s, Boruvka’s) are greedy

  • Building block — used as a subroutine in approximation algorithms for harder problems (TSP, Steiner tree)

  • Applications everywhere — networks, clustering, image analysis, error-correcting codes

Applications of MST

  • Minimum Spanning Tree (MST)
  • Applications of MST
  • Cuts and the Cut Property
  • The Cycle Property
  • Union-Find Data Structure
  • Correctness of Kruskal’s Algorithm
  • Summary

Applications of MST

  • Network Design (STP) — Ethernet switches use the Spanning Tree Protocol (IEEE 802.1D) to compute an MST of the network topology, preventing broadcast storms while maintaining connectivity.

  • Clustering — Single-linkage clustering computes an MST of data points; removing the k-1 heaviest edges gives k clusters. Used in phylogenetics, customer segmentation, image segmentation.

  • Approximation Algorithms — Metric TSP uses MST for a 2-approximation; Steiner tree uses MST on terminal pairs for a 2-approximation; facility location via MST dual fitting.

  • Other uses — LDPC error-correcting codes, medical image registration (Renyi entropy), bioinformatics (protein sequence alignment), RSTP for mesh networks.

Cuts and the Cut Property

  • Minimum Spanning Tree (MST)
  • Applications of MST
  • Cuts and the Cut Property
  • The Cycle Property
  • Union-Find Data Structure
  • Correctness of Kruskal’s Algorithm
  • Summary

Graph Cut

In a graph G=(V, E) a cut is a bipartition of V into sets S, V-S for some S\subseteq V. We show it by (S,V-S).

An edge e=\{u,v\} crosses the cut (S, V-S) if exactly one of u,v is in S.

Cut Property

Let S be any subset of nodes (called a cut), and let e = \{u, v\} be the minimum cost edge crossing (S, V-S). Then every MST contains e.

Proof. Proof. Suppose e does not belong to some MST T^*.

  1. Adding e to T^* creates a cycle C.
  2. Since e crosses (S, V-S), C must contain some other edge f that also crosses (S, V-S).
  3. T = T^* \cup \{e\} - \{f\} is also a spanning tree.
  4. Since c_e < c_f (by assumption, e is the cheapest crossing edge), \text{cost}(T) < \text{cost}(T^*).
  5. This contradicts T^* being an MST. \square

The Cycle Property

  • Minimum Spanning Tree (MST)
  • Applications of MST
  • Cuts and the Cut Property
  • The Cycle Property
  • Union-Find Data Structure
  • Correctness of Kruskal’s Algorithm
  • Summary

Cycle Property

Let C be any cycle in G, and let f be the maximum cost edge in C. Then the MST T^* does not contain f.

Proof. Proof. Suppose f belongs to T^*.

  1. Deleting f from T^* disconnects T^* into two components — let S be one side of this cut.
  2. Since f \in C, the cycle C must contain some other edge e that also crosses (S, V-S).
  3. T = T^* \cup \{e\} - \{f\} is also a spanning tree.
  4. Since c_e < c_f (by assumption, f is the most expensive in C), \text{cost}(T) < \text{cost}(T^*).
  5. This contradicts T^* being an MST. \square

Cut / Cycle Properties — Intuition

  • Cut property: Heavy edges can’t go in, light edges can’t stay out.
  • Cycle property: The heaviest edge in any cycle is never needed.
  • Together, these two properties completely characterize the MST: an edge belongs to some MST iff there exists a cut for which it is lightest, and to every MST iff it is the unique lightest edge in some cut.

Kruskal’s Algorithm

Algorithm:

  1. Sort edges by weight.
  2. F \gets \emptyset.
  3. For each (u,v): add if different components, else skip.

Step 0 / 9 — click ▶

pending   MST   skip

Union-Find Data Structure

  • Minimum Spanning Tree (MST)
  • Applications of MST
  • Cuts and the Cut Property
  • The Cycle Property
  • Union-Find Data Structure
  • Correctness of Kruskal’s Algorithm
  • Summary

The Problem: Cycle Detection

Kruskal’s algorithm needs to check: are u and v already in the same connected component?

  • Naively: DFS from u each time \Rightarrow O(V) per check \Rightarrow O(EV) total.
  • We need a data structure that supports:
    • find(u) — which component does u belong to?
    • union(u, v) — merge the components of u and v.

Union-Find (a.k.a. Disjoint Set Union, DSU) handles both in nearly constant time.

Union-Find: Basic Operations

  • makeset(x): Create a new set containing just x.
    • Each element initially points to itself as its set’s representative.
  • find(x): Return the representative of the set containing x.
    • Follow parent pointers until reaching the root.
  • union(x, y): Merge the sets containing x and y.
    • If \text{find}(x) \neq \text{find}(y), make one root point to the other.
Operation Without optimization With optimizations
makeset O(1) O(1)
find O(\text{depth}) O(\alpha(n))
union O(\text{depth}) O(\alpha(n))

Union-Find: Union by Rank

Problem: Naively linking roots can create a chain (depth O(n), making find slow).

Solution (Union by Rank): Keep track of the height (rank) of each tree. Always attach the shorter tree under the taller one.

union(x, y):
    rx = find(x), ry = find(y)
    if rx == ry: return
    if rank[rx] < rank[ry]: swap(rx, ry)
    parent[ry] = rx
    if rank[rx] == rank[ry]: rank[rx] += 1
  • Result: Tree depth is O(\log n) — good, but we can do better.

Union-Find: Path Compression

Idea: During find(x), after finding the root, make every node on the path point directly to the root.

find(x):
    if parent[x] != x:
        parent[x] = find(parent[x])
    return parent[x]
  • Effect: Future find calls on the same chain are O(1).
  • Amortized analysis: Any sequence of m operations on n elements runs in O(m\, \alpha(n)) time, where \alpha(n) is the inverse Ackermann function.
    • \alpha(n) \le 4 for all n \le 2^{2^{2^{2^{16}}}} (essentially constant).

Kruskal’s with Union-Find

KruskalMST(G, w):
    for each vertex v in V:            # makeset × |V|
        makeset(v)

    sort edges E by weight w           # O(E log E)

    F = ∅
    for each edge (u, v) in E:         # O(E α(V))
        if find(u) ≠ find(v):
            union(u, v)
            F = F ∪ {(u, v)}
            if |F| == |V| - 1: break

    return F

Time complexity:

  • Sorting: O(E \log E) = O(E \log V)
  • V makeset + 2E find + (V-1) union: O((E+V)\,\alpha(V)) = O(E\,\alpha(V))
  • Total: O(E \log V) — dominated by sorting.

Correctness of Kruskal’s Algorithm

  • Minimum Spanning Tree (MST)
  • Applications of MST
  • Cuts and the Cut Property
  • The Cycle Property
  • Union-Find Data Structure
  • Correctness of Kruskal’s Algorithm
  • Summary

Correctness — Overview

Kruskal’s algorithm correctly computes an MST.

We prove this by a greedy exchange argument:

  1. Let F be the set of edges built by Kruskal’s so far.
  2. Invariant: F is always a subset of some MST M.
  3. The invariant holds initially (F = \emptyset).
  4. When we add e to F, we show there exists an MST M' containing F \cup \{e\}.

Correctness — Exchange Step

Case 1: e \in M. Trivial — set M' = M, invariant preserved.

Case 2: e \notin M. Then M \cup \{e\} contains a cycle C.

  • Kruskal’s added e, so the endpoints of e were in different components of F.
  • Following C around M, there must be some other edge e' \in C whose endpoints are also in different components of F.
  • Since Kruskal’s chose e over e', we have w(e) \le w(e').

Construct M' = M \cup \{e\} - \{e'\}:

  • M' is a spanning tree (same size, still connected).
  • \text{cost}(M') = \text{cost}(M) + w(e) - w(e') \le \text{cost}(M).
  • Since M is an MST, M' is also an MST.
  • And F \cup \{e\} \subseteq M'. \square

Correctness — Key Insight

The exchange argument is the heart of greedy correctness proofs:

  1. Compare your solution to any optimal solution.
  2. Find the first point where they differ.
  3. Swap the greedy edge into the optimal solution without making it worse.
  4. Repeat — the greedy solution is also optimal.

We will see this pattern again in Prim’s algorithm, Huffman codes, and Matroids.

Summary

  • Minimum Spanning Tree (MST)
  • Applications of MST
  • Cuts and the Cut Property
  • The Cycle Property
  • Union-Find Data Structure
  • Correctness of Kruskal’s Algorithm
  • Summary

What We Learned Today

  • MST definition — minimum-weight spanning tree in a graph

  • Cut and Cycle properties — fundamental characterizations of MST edges

  • Kruskal’s algorithm — repeatedly add the cheapest non-cycle-creating edge

  • Union-Find — efficient cycle detection via DSU with path compression and union by rank

  • Correctness proof — greedy exchange argument

Technique Time complexity
Kruskal’s + Union-Find O(E \log V)
Kruskal’s + Union-Find (edges pre-sorted) O(E\,\alpha(V))