849
BOS
PVD
A crucial fact
The Prim-Jarnik Algorithm (§7.3.2)
ORD 187
740 144
1846 621 JFK
184 1258
802
SFO BWI
1391
1464
337 1090
Partition Property U V
Prim-Jarnik’s Algorithm
f 7
Partition Property: 4 Similar to Dijkstra’s algorithm (for a connected graph)
Consider a partition of the vertices of 9 We pick an arbitrary vertex s and we grow the MST as a
G into subsets U and V 2 5
8 cloud of vertices, starting from s
Let e be an edge of minimum weight
across the partition 8 e 3 We store with each vertex v a label d(v) = the smallest
There is a minimum spanning tree of
7 weight of an edge connecting v to a vertex in the cloud
G containing edge e
Proof: Replacing f with e yields At each step:
Let T be an MST of G
another MST We add to the cloud the
If T does not contain e, consider the U V vertex u outside the cloud
cycle C formed by e with T and let f f 7 with the smallest distance
be an edge of C across the partition 4 label
By the cycle property, 9 We update the labels of the
weight(f) ≤ weight(e) 2 5
8 vertices adjacent to u
Thus, weight(f) = weight(e)
8 e 3
We obtain another MST by replacing
f with e 7
Minimum Spanning Trees 5 Minimum Spanning Trees 6
1
Minimum Spanning Tree 5/13/2002 4:52 PM
2
Minimum Spanning Tree 5/13/2002 4:52 PM
Representation of a Partition-Based
Partition Implementation
Each set is stored in a sequence A partition-based version of Kruskal’s Algorithm
Each element has a reference back to the set performs cloud merges as unions and tests as finds.
Algorithm Kruskal(G):
operation find(u) takes O(1) time, and returns the set of
which u is a member. Input: A weighted graph G.
Output: An MST T for G.
in operation union(u,v), we move the elements of the
smaller set to the sequence of the larger set and update Let P be a partition of the vertices of G, where each vertex forms a separate set.
their references Let Q be a priority queue storing the edges of G, sorted by their weights
Let T be an initially-empty tree
the time for operation union(u,v) is min(nu,nv), where nu
and nv are the sizes of the sets storing u and v while Q is not empty do
(u,v) ← Q.removeMinElement()
Whenever an element is processed, it goes into a if P.find(u) != P.find(v) then
set of size at least double, hence each element is Running time:
Add (u,v) to T
processed at most log n times O((n+m)log n)
P.union(u,v)
return T
Minimum Spanning Trees 13 Minimum Spanning Trees 14
Kruskal
Example 2704
867 BOS
Example 2704
867 BOS
Example 2704
867 BOS Example 2704
867 BOS
3
Minimum Spanning Tree 5/13/2002 4:52 PM
Example 2704
867 BOS Example 2704
867 BOS
Example 2704
867 BOS Example 2704
867 BOS
Example 2704
867 BOS Example 2704
867 BOS
4
Minimum Spanning Tree 5/13/2002 4:52 PM
Example 2704
867 BOS Example 2704
867 BOS
Example 2704
867 BOS Example 2704
BOS
867
849 PVD 849 PVD
ORD 187
ORD 187
740 144
1846 JFK 740 144
621 1846 JFK
621
184 1258
802 184 1258
SFO 802
1391 BWI SFO
1391 BWI
1464
337 1090 1464
337 1090
DFW 946
LAX 1235 DFW 946
LAX 1235
1121
1121
MIA
MIA
2342
2342
Minimum Spanning Trees 27 Minimum Spanning Trees 28
Baruvka
Baruvka’s Algorithm Example 2704
867 BOS
5
Minimum Spanning Tree 5/13/2002 4:52 PM
Example 2704
867 BOS Example 2704
867 BOS