Reaves.dev

v0.1.0

built using

Phoenix v1.7.17

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:

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

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

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