Download - 23.Minimum spanning tree
![Page 1: 23.Minimum spanning tree](https://reader036.vdocuments.us/reader036/viewer/2022062411/56814c2d550346895db9335a/html5/thumbnails/1.jpg)
23.Minimum spanning tree
![Page 2: 23.Minimum spanning tree](https://reader036.vdocuments.us/reader036/viewer/2022062411/56814c2d550346895db9335a/html5/thumbnails/2.jpg)
Chapter 23 P.2
Computer Theory Lab.
Let G=(V,E) be a connected, undirected graph. For each edge
Evu ),( , we have a weight w(u,v) specifying the cost to connect
u and v. We wish to find an acyclic subset ET that connects
all of the vertices and whose total weight
Tvu
vuwTw),(
),()( is
minimized. Since T is acyclic and connects all of the vertices, it
must form a tree, which we call a spanning tree. We call the
problem of determine
the tree T the
minimum spanning
tree problem.
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4
![Page 3: 23.Minimum spanning tree](https://reader036.vdocuments.us/reader036/viewer/2022062411/56814c2d550346895db9335a/html5/thumbnails/3.jpg)
Chapter 23 P.3
Computer Theory Lab.
23.1 Growing a minimum spanning tree
GENERIC-MST(G, w) 1 A
2 while A does not form a spanning tree
3 do find an edge (u, v) that is safe for A
4 A A u v {( , )}
5 return A
![Page 4: 23.Minimum spanning tree](https://reader036.vdocuments.us/reader036/viewer/2022062411/56814c2d550346895db9335a/html5/thumbnails/4.jpg)
Chapter 23 P.4
Computer Theory Lab.
A cut (S,V-S) of an undirected graph G = (V,E) is a partition of V. We
say that an edge Evu ),( crosses the cut (S,V-S) if one of its
endpoints is in S and the other is in V-S. We say a cut respects the set
A of edges if no edge in A crosses the cut. An edge is a light edge
crossing a cut if its weight is the minimum of any edge crossing the cut.
Note that there can be more than one light edge crossing a cut in case
of ties.
![Page 5: 23.Minimum spanning tree](https://reader036.vdocuments.us/reader036/viewer/2022062411/56814c2d550346895db9335a/html5/thumbnails/5.jpg)
Chapter 23 P.5
Computer Theory Lab.
a
c
i
g f
e
d
h
b
8
4
8
11
7
1
14
10
92
6
7
2
4
S
V-S
a
c
i
g
fe
d
h
b
8
4
8
11
7
1
14
10
9
2
6
7
2
4
S V-S
![Page 6: 23.Minimum spanning tree](https://reader036.vdocuments.us/reader036/viewer/2022062411/56814c2d550346895db9335a/html5/thumbnails/6.jpg)
Chapter 23 P.6
Computer Theory Lab.
Theorem 23.1. Let G = (V, E) be a
connected undirected graph with a
real-valued weight function w defined on
E. Let A be a subset of E that is
included in some minimum spanning tree
for G, let (S, V-S) be any cut of G that
respects A, and let (u, v) be a light edge
crossing (S, V-S). Then, edge (u, v) is
safe for A.
x
y
v
u P
![Page 7: 23.Minimum spanning tree](https://reader036.vdocuments.us/reader036/viewer/2022062411/56814c2d550346895db9335a/html5/thumbnails/7.jpg)
Chapter 23 P.7
Computer Theory Lab.
Corollary 23.2. Let G = (V, E) be a connected, undirected graph with
a real-valued weighted function w defined on E. Let A be a subset of E
that is induced in some minimum spanning tree for G, and let C be a
connected component (tree) in the forest G V AA ( , ). If (u,v) is a light
edge connecting C to some other component GA , then (u, v) is safe for
A.
![Page 8: 23.Minimum spanning tree](https://reader036.vdocuments.us/reader036/viewer/2022062411/56814c2d550346895db9335a/html5/thumbnails/8.jpg)
Chapter 23 P.8
Computer Theory Lab.
23.2 The algorithms of Kruskal and PrimMST_KRUSKAL(G, w)
1 A
2 for each vertex v V G [ ]
3 do MAKE-SET(v)
4 sort the edge of E by nondecreasing weight w
5 for each edge ( , )u v E , in order by
nondecreasing weight
6 do if FIND_SET(u)FIND_SET(v)
7 then A A u v {( , )}
8 UNION(u, v)
9 return A Complexity O(E log E)
![Page 9: 23.Minimum spanning tree](https://reader036.vdocuments.us/reader036/viewer/2022062411/56814c2d550346895db9335a/html5/thumbnails/9.jpg)
Chapter 23 P.9
Computer Theory Lab.
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4
![Page 10: 23.Minimum spanning tree](https://reader036.vdocuments.us/reader036/viewer/2022062411/56814c2d550346895db9335a/html5/thumbnails/10.jpg)
Chapter 23 P.10
Computer Theory Lab.
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4 a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4 a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4
Continue ……
![Page 11: 23.Minimum spanning tree](https://reader036.vdocuments.us/reader036/viewer/2022062411/56814c2d550346895db9335a/html5/thumbnails/11.jpg)
Chapter 23 P.11
Computer Theory Lab.
Prim’s algorithmMST_PRIM(G, w, r)
1 Q V G [ ]
2 for each u Q
3 do key u[ ]
4 key r[ ] 0
5 [ ]r NIL
6 while Q
7 do u ECTRACT MIN Q _ ( )
8 for each v Adj u [ ]
9 do if v Q and w u v key v( , ) [ ]
10 then [ ]u u
11 key v w u v[ ] ( , )
Complexity: O(V log V + E log V), or O(E + V log V)
![Page 12: 23.Minimum spanning tree](https://reader036.vdocuments.us/reader036/viewer/2022062411/56814c2d550346895db9335a/html5/thumbnails/12.jpg)
Chapter 23 P.12
Computer Theory Lab.
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4
![Page 13: 23.Minimum spanning tree](https://reader036.vdocuments.us/reader036/viewer/2022062411/56814c2d550346895db9335a/html5/thumbnails/13.jpg)
Chapter 23 P.13
Computer Theory Lab.
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4
a
c
i
g f
e
d
h
b
8
48
117
1
14
10
926
7
2
4