Lecture 18 - Minimum spanning trees (MSTs)

Date Pre-lecture slides Post-lecture scribbles Async video Lecture recording
October 30 2025 Lecture 18 - Minimum spanning trees (MSTs) Lecture 18 - Minimum spanning trees (MSTs) Lecture 18 - Minimum spanning trees (MSTs) Lecture 18 - Minimum spanning trees (MSTs)
 

Notes

Minimum Spanning Trees

Definition

Example:

text text text

Applications

Basic Properties

Cuts

Given a graph G = (V, E), a cut is a partition of the vertices of the graph into two sets (S, V \ S).

Safe and Unsafe edges

Safe edge

text

Unsafe edge

text

Spanning tree properties

Algorithms

Relevent LeetCode Practice (by Tristan Yang)

  1. LeetCode 1584 — Min Cost to Connect All Points (Medium)
    • Relevance: It’s a pure MST problem on a complete graph of points with Manhattan distance weights. Great for demonstrating Prim’s vs Kruskal’s approaches and complexity considerations (dense graph).
    • ECE 374 Process: Model as complete graph with Manhattan distance weights. Use Prim’s algorithm: start from arbitrary point, maintain minimum edge weights to growing MST, extract-min and update keys. Implement in $O(n^2)$ time using array or $O(m \log n)$ with min-heap. Alternatively use Kruskal’s: sort all edges by weight, use Union-Find to connect components, stop after $n-1$ edges added.
    • Resource: LeetCode editorial for Min Cost to Connect All Points.
    • Takeaway: The MST total cost is invariant of the starting node. Prim’s and Kruskal’s are two greedy methods to find MSTs. The cut property guarantees that the smallest edge crossing any cut is safe to include (underpins both algorithms).
  2. LeetCode 1135 — Connecting Cities With Minimum Cost (Medium)
    • Relevance: A textbook example of Kruskal’s algorithm with a graph given by a list of edges (usually sparser than the complete graph in problem 1584).
    • ECE 374 Process: Sort the given edges by weight. Iterate through them in increasing order and use DSU to keep track of components. Union the endpoints of an edge if they are currently in different components (include that edge in the MST). Stop when you’ve added $n-1$ edges or if you run out of edges before fully connecting (then it’s impossible to connect all cities).
    • Resource: LeetCode editorial for Connecting Cities With Minimum Cost.
    • Takeaway: Kruskal’s correctness comes from the cut property: the cheapest edge that connects two separate components is always part of some MST. Using DSU, we implement this efficiently in $O(m \log m)$ time (sorting edges dominates).
  3. LeetCode 684 — Redundant Connection (Medium)
    • Relevance: This problem uses DSU to detect cycles by processing edges one by one, effectively mirroring the cycle-detection step in Kruskal’s algorithm.
    • ECE 374 Process: Start with $n$ isolated nodes. For each edge, check if its two endpoints are already in the same component via DSU. If not, union them (connect the components); if yes, that edge would create a cycle and is therefore the redundant one (return it). This is exactly how Kruskal “skips” edges that would form a cycle.
    • Resource: LeetCode editorial for Redundant Connection.
    • Takeaway: Union-Find is a powerful tool for cycle detection in an undirected graph. It underpins Kruskal’s MST algorithm by efficiently determining whether adding an edge will form a cycle.

Supplemental Problems

Additional Resources

Contributors

Sandhya Perumenki