Minimum spanning tree
Jean Cousty MorphoGraph and Imagery
2011
Outline of the lecture
1 Minimum spanning tree
2 Cut theorem for MST
3 Kruskal algorithm
Minimum spanning tree
Edge weighted graph
G denotes a connected undirected graph (E,Γ)
W denotes a map from Γ into R
W(u) is called the weight (or value) of u (∀u ∈Γ) The pair (G,W) is called an(edge-) weighted graph
Minimum spanning tree
Edge weighted graph
G denotes a connected undirected graph (E,Γ) W denotes a map from Γ into R
W(u) is called the weight (or value) of u (∀u ∈Γ)
The pair (G,W) is called an(edge-) weighted graph
Minimum spanning tree
Edge weighted graph
G denotes a connected undirected graph (E,Γ) W denotes a map from Γ into R
W(u) is called the weight (or value) of u (∀u ∈Γ) The pair (G,W) is called an(edge-) weighted graph
Minimum spanning tree
Spanning subgraph
Definition
A spanning subgraph ofG is a graph(E,Γ0) such thatΓ0 ⊆Γ
Minimum spanning tree
Weight of a subgraph
Definition
Let G0 = (E,Γ0) be a spanning subgraph of G
The weight ofG0, denoted by W(G0), is the sum of the weights of the edges that belong to Γ0
W(G) =P
{W(u)|u∈Γ0}
Minimum spanning tree
Minimum spanning tree (MST)
Definition
A minimum spanning tree (for (G,W))is a connected spanning subgraph G0= (E,Γ0) of G whose weight is minimum:
for any connected spanning subgraph G00of G , if W(G00)≤W(G0) then W(G00) =W(G0)
Property
If G0 is an MST, then G0 is a tree
Minimum spanning tree
Minimum spanning tree (MST)
Definition
A minimum spanning tree (for (G,W))is a connected spanning subgraph G0= (E,Γ0) of G whose weight is minimum:
for any connected spanning subgraph G00of G , if W(G00)≤W(G0) then W(G00) =W(G0)
Property
If G0 is an MST, then G0 is a tree
Minimum spanning tree
Illustration
Minimum spanning tree
Maximum spanning tree (MaxST)
Definition
A maximum spanning tree (for (G,W))is a spanning tree(E,Γ0) of maximum weight:
for any spanning tree G00, if W(G00)≥W(G0) then W(G00) =W(G0)
Property
G0 is a MaxST of(G,W)if and only if G0 is a MST of (G,−W)
Minimum spanning tree
Maximum spanning tree (MaxST)
Definition
A maximum spanning tree (for (G,W))is a spanning tree(E,Γ0) of maximum weight:
for any spanning tree G00, if W(G00)≥W(G0) then W(G00) =W(G0)
Property
G0 is a MaxST of(G,W)if and only if G0 is a MST of (G,−W)
Minimum spanning tree
MST algorithm and safe edges
Generic MST Algorithm ( Data: (E,Γ,W) ;
Result: Γ0 such that (E,Γ0) is an MST)
n :=|E|; Γ0:=∅ ;k := 0 ; While k <n−1do
Find an edgeuthat issafefor Γ0 Γ0 := Γ0∪ {u}
Definition
Let(E,Γ0) be a subgraph of a MST Let u∈Γ\Γ0
u issafe forΓ0 if(E,Γ0∪ {u}) is also a subgraph of an MST
Minimum spanning tree
MST algorithm and safe edges
Generic MST Algorithm ( Data: (E,Γ,W) ;
Result: Γ0 such that (E,Γ0) is an MST)
n :=|E|; Γ0:=∅ ;k := 0 ; While k <n−1do
Find an edgeuthat issafefor Γ0 Γ0 := Γ0∪ {u}
Definition
Let (E,Γ0) be a subgraph of a MST Let u ∈Γ\Γ0
Cut theorem for MST
Cut and MST
Question
How to efficiency detect an edge that is safe?
Cut theorem for MST
Cut
Definition
Let Γ0 ⊆Γ
The cut induced by Γ0 is the subset of Γthat contains the edges that link two distinct connected components of the graph (E,Γ0)
A subset C ofΓ is a cutif there existsΓ0⊆Γsuch that C is the cut induced byΓ0
Cut theorem for MST
Cut
Definition
Let Γ0 ⊆Γ
The cut induced by Γ0 is the subset of Γthat contains the edges that link two distinct connected components of the graph (E,Γ0) A subset C ofΓ is a cutif there existsΓ0⊆Γsuch that C is the cut induced by Γ0
Cut theorem for MST
Cut theorem for MST
Theorem
Let (E,Γ0) be a subgraph of an MST
Let C be a cut that is a subset of the cut induced byΓ0 Let u∈C be an edge of minimum weight in C (i.e.,∀v ∈C , W(u)≤W(v))
Then, u is safe forΓ0
Cut theorem for MST
Cut theorem for MST
Theorem
Let (E,Γ0) be a subgraph of an MST
Let C be a cut that is a subset of the cut induced by Γ0
Let u∈C be an edge of minimum weight in C (i.e.,∀v ∈C , W(u)≤W(v))
Then, u is safe forΓ0
Cut theorem for MST
Cut theorem for MST
Theorem
Let (E,Γ0) be a subgraph of an MST
Let C be a cut that is a subset of the cut induced by Γ0 Let u ∈C be an edge of minimum weight in C (i.e.,∀v ∈C , W(u)≤W(v))
Then, u is safe forΓ0
Cut theorem for MST
Cut theorem for MST
Theorem
Let (E,Γ0) be a subgraph of an MST
Let C be a cut that is a subset of the cut induced by Γ0 Let u ∈C be an edge of minimum weight in C (i.e.,∀v ∈C , W(u)≤W(v))
Then, u is safe for Γ0
Kruskal algorithm
MST computation
KRUSKAL Algorithm ( Data: a connected graph (E,Γ,W) ; Result: Γ0 such that (E,Γ0) is an MST)
n :=|E|; Γ0:=∅ ;k := 0 ;i := 1;
Sort the edges in Γ in increasing order of weight:
Find the sequence (u1, . . . ,um) such that Γ ={u1, . . . ,um} and W(ui−1)≤W(ui),∀i ∈ {2, . . . ,m}
While k <n−1Do {xi,yi}:=ui ;
Ifxi ∈/ the connected component containingyi in (E,Γ0)Then Γ0:= Γ0∪ {ui};
k:=k+ 1;
Kruskal algorithm
Execution example
Kruskal algorithm
Proof of the algorithm
When the testIf is positive, the edgeu is safe for Γ0
This can be proved by the cut theorem applied to the cut induced by Γ0
Kruskal algorithm
Complexity of Kruskal Algorithm
Complexity
Complexity of a sort (O(mlog(m))for quick sort)
Complexity of theWhile loop: O(m)
Complexity of theIf test: O(m×n)(connected component algorithm seen in the course)
Overall complexity: O(m×n+mlog(m))
The complexity of theIftest can be reduced to quasi linear time using Tarjan’s union of disjoint set algorithm
Kruskal algorithm
Complexity of Kruskal Algorithm
Complexity
Complexity of a sort (O(mlog(m))for quick sort) Complexity of the While loop: O(m)
Complexity of theIf test: O(m×n)(connected component algorithm seen in the course)
Overall complexity: O(m×n+mlog(m))
The complexity of theIftest can be reduced to quasi linear time using Tarjan’s union of disjoint set algorithm
Kruskal algorithm
Complexity of Kruskal Algorithm
Complexity
Complexity of a sort (O(mlog(m))for quick sort) Complexity of the While loop: O(m)
Complexity of the If test: O(m×n)(connected component algorithm seen in the course)
Overall complexity: O(m×n+mlog(m))
The complexity of theIftest can be reduced to quasi linear time using Tarjan’s union of disjoint set algorithm
Kruskal algorithm
Complexity of Kruskal Algorithm
Complexity
Complexity of a sort (O(mlog(m))for quick sort) Complexity of the While loop: O(m)
Complexity of the If test: O(m×n)(connected component algorithm seen in the course)
Overall complexity: O(m×n+mlog(m))
The complexity of theIftest can be reduced to quasi linear time using Tarjan’s union of disjoint set algorithm
Kruskal algorithm
Complexity of Kruskal Algorithm
Complexity
Complexity of a sort (O(mlog(m))for quick sort) Complexity of the While loop: O(m)
Complexity of the If test: O(m×n)(connected component algorithm seen in the course)
Overall complexity: O(m×n+mlog(m))
The complexity of the Iftest can be reduced to quasi linear time using Tarjan’s union of disjoint set algorithm
Kruskal algorithm
Prim and Boruvka Algorithm
These are other algorithms for computing an MST Also a version of the generic algorithm
Their invariants also rely on the cut theorem
Read http://www.ics.uci.edu/˜eppstein/161/960206.html