Reaves.dev

v0.1.0

built using

Phoenix v1.7.20

Minimum Spanning Tree

Stephen M. Reaves

::

2025-02-17

Greedy algorithms to find minimum spanning tree

Summary

We found a greedy algorithm to construct MSTs by partitioning graphs and using cut edges

Contents

MST Problem

Given: Undirected graph G, with weights w for e in E.

Goal: Find minimal size, connected subgraph with min weight

Tree Properties

Tree
connected, acyclic graph

Basic properties:

  • n vertices = n-1 edges
  • exactly 1 path between every pair of vertices
    • if there are 0 paths, tree is not connected
    • if there are 2 or more, there is a cycle
  • Any connected G=(V,E) with E=V1 G=(V,E) \text{ with } \lvert E \rvert = \lvert V \rvert - 1 is a tree

Kruskal’s Algorithm

Gaba--b1cb--c2ib--i12dc--d3ed--e4ld--l9fe--f5f--a6hf--h12mh--m7nh--n7ji--j9ki--k7j--k12j--l12k--c9k--l12n--l9on--o9po--p12qo--q7p--l12p--q9rq--r7

Sort edges by lowest weight, iterate over edges, add them to the tree if you can

Gaba--b1cb--c2ib--i12dc--d3ed--e4ld--l9fe--f5f--a6hf--h12mh--m7nh--n7ji--j9ki--k7j--k12j--l12k--c9k--l12n--l9on--o9po--p12qo--q7p--l12p--q9rq--r7
Gaba--b1cb--c2ib--i12dc--d3ed--e4ld--l9fe--f5f--a6hf--h12mh--m7nh--n7ji--j9ki--k7j--k12j--l12k--c9k--l12n--l9on--o9po--p12qo--q7p--l12p--q9rq--r7
Gaba--b1cb--c2ib--i12dc--d3ed--e4ld--l9fe--f5f--a6hf--h12mh--m7nh--n7ji--j9ki--k7j--k12j--l12k--c9k--l12n--l9on--o9po--p12qo--q7p--l12p--q9rq--r7
Gaba--b1cb--c2ib--i12dc--d3ed--e4ld--l9fe--f5f--a6hf--h12mh--m7nh--n7ji--j9ki--k7j--k12j--l12k--c9k--l12n--l9on--o9po--p12qo--q7p--l12p--q9rq--r7
Gaba--b1cb--c2ib--i12dc--d3ed--e4ld--l9fe--f5f--a6hf--h12mh--m7nh--n7ji--j9ki--k7j--k12j--l12k--c9k--l12n--l9on--o9po--p12qo--q7p--l12p--q9rq--r7

We cannot add the edge of weight 6 since it would create a cycle

Gaba--b1cb--c2ib--i12dc--d3ed--e4ld--l9fe--f5f--a6hf--h12mh--m7nh--n7ji--j9ki--k7j--k12j--l12k--c9k--l12n--l9on--o9po--p12qo--q7p--l12p--q9rq--r7
Gaba--b1cvb--c2ib--i12dc--d3ed--e4ld--l9fe--f5f--a6hf--h12mh--m7nh--n7ji--j9kwi--k7j--k12j--l12k--c9k--l12n--l9on--o9po--p12qo--q7p--l12p--q9rq--r7

It takes O(mlogn) time to sort edges by weight

It takes O(logn) time to find if adding an edge creates a cycle

  • Using Union-Find data structure
  • Searches to see if nodes are in same component

Kruskal’s Correctness

Assume by induction tree X is correct so far

xT x \subset T where T is MST

If for some edge e, we don’t add e to x, x is still MST.

If for some edge e, we do add e to x, xeT x \bigcup e \subset T' where T’ is a MST

We know T’ is minimum becuase e is of minimum (remaining) weight

Cuts

Cut
S set of edges that partition the vertices into two sets
Gcluster_acluster_caba--bda--dcb--ceb--ec--dfd--fge--ghf--h

Cut Property

For an undirected Graph G

  • Take XE X \subset E where XT X \subset T for an MST T
  • Take ST S \subset T where no edge is in the cut(S,Sˉ) \text{cut}\left(S,\bar{S}\right)
  • Look at all edges of G in cut(S,Sˉ) \text{cut}\left(S,\bar{S}\right)
  • Let e e^* be a minimum weight edge in cut

Then XeT X \bigcup e^* \subset T' where T’ is an MST

If we start with disjoint subsets and only consider minimal edges going between them adding the edge will create a new MST