0% found this document useful (0 votes)
37 views20 pages

Nothing Specail 4

The document discusses minimum spanning trees and algorithms for finding them. It explains what a minimum spanning tree is and provides examples of Prim's and Kruskal's algorithms, two common algorithms for finding minimum spanning trees in graphs.

Uploaded by

spectre194523
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views20 pages

Nothing Specail 4

The document discusses minimum spanning trees and algorithms for finding them. It explains what a minimum spanning tree is and provides examples of Prim's and Kruskal's algorithms, two common algorithms for finding minimum spanning trees in graphs.

Uploaded by

spectre194523
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Minimum Spanning Trees

Discrete Mathematics

Minimum Spanning Trees 1


Example: Minimum Road System

Farnham Trois-Rivières
200 100
150 150
Sherbrooke 170
200 200 Bedford
200 Cowansville
160

Granby

In winter, the highway department wants to plow the fewest roads


so that there will always be cleared roads connecting any two
towns, but at the lowest possible cost.

Minimum Spanning Trees 2


Example: Minimum Road System

Farnham Trois-Rivières
200 100
150 150
Sherbrooke 170
200 200 Bedford
200 Cowansville
160

Granby
Farnham Trois-Rivières
100
150 150
Sherbrooke 170
Bedford
Cowansville
160

Granby

Minimum Spanning Trees 3


Minimum Spanning Tree

Definition
A minimum spanning tree, in a connected weighted graph, is a
spanning tree that has the smallest possible sum of weights of its
edges.

Minimum Spanning Trees 4


Prim’s Algorithm

Robert C. Prim, Shortest connection networks and some


generalizations, Bell System Techn. J. vol 36 (1957)
pp. 1389–1401.

Minimum Spanning Trees 5


Prim’s Algorithm

procedure Prim (G : weighted connected undirected graph


with n vertices)
T := a minimum weight edge
for i := 1 to n − 2
begin
e := an edge of minimum weight incident to a vertex
in T and not forming a simple circuit in T
if added to T .
T := T with e added
end
{T is a minimum spanning tree of G }

Minimum Spanning Trees 6


Example of Prim’s Algorithm, Step 1 of 5

a 2 b 3 c 1 d

3 1 2 5
4 f 3 g 3
e h

4 2 4 3
3 3 1

i j k l

Find the edges {b, f }, {c, d} and {k, l } with minimum cost.

Minimum Spanning Trees 7


Example of Prim’s Algorithm, Step 2 of 5

a 2 b 3 c 1 d

3 1 2 5
4 f 3 g 3
e h

4 2 4 3
3 3 1

i j k l

Initialise the minimum spanning tree T with the edge {b, f }, which
is the first in lexicographic order amongst the minimum edges.

Minimum Spanning Trees 8


Example of Prim’s Algorithm, Step 3 of 5

a 2 b 3 c 1 d

3 1 2 5
4 f 3 g 3
e h

4 2 4 3
3 3 1

i j k l

Add the edges {a, b} and {f , j} to T .

Minimum Spanning Trees 9


Example of Prim’s Algorithm, Step 4 of 5

a 2 b 3 c 1 d

3 1 2 5
4 f 3 g 3
e h

4 2 4 3
3 3 1

i j k l

Add the edges {a, e}, {i , j} and {f , g } to T

Minimum Spanning Trees 10


Example of Prim’s Algorithm, Step 5 of 5

a 2 b 3 c 1 d

3 1 2 5
4 f 3 g 3
e h

4 2 4 3
3 3 1

i j k l

Add the edges {c, g }, {c, d}, {g , h}, {h, l } and {k, l } to T .

Minimum Spanning Trees 11


Example of Prim’s Algorithm

a 2 b c 1 d

3 1 2
f 3 g 3
e h

2 3
3 1

i j k l

Final Solution. T is a minimum spanning tree of the graph G .

Minimum Spanning Trees 12


Joseph B. Kruskal

Room 2C-281, Bell Labora-


tories, Lucent Technologies,
700 Mountain Av. Murray
Hill, NJ 07974-0636, phone:
(908) 582-3853, kruskal@bell-
labs.com cm.bell-labs.com/cm/ms/
departments/sia/kruskal

On the Shortest Spanning Subtree


of a Graph and the Traveling Sales-
man Problem, Proc. Amer. Math.
Soc., vol 7, no 1 (Feb. 1956),
pp. 48–50.

Minimum Spanning Trees 13


Kruskal’s Algorithm

procedure Kruskal (G : weighted connected undirected graph


with n vertices)
T := empty tree
list := list of edges of G sorted by weight
while T has less than n − 1 edges
begin
e := next edge in the list
if e does not form a simple circuit
when added to T ,
then T := T with e added.
end
{T is a minimum spanning tree of G }

Minimum Spanning Trees 14


Difference between Prim’s and Kruskal’s Algorithms

Note the difference between Prim’s and Kruskal’s algorithms. In


Prim’s algorithm, edges of minimum weight that are incident to a
vertex already in the tree, and not forming a circuit, are chosen.
In Kruskal’s algorithm, edges of minimum weight that are not
necessarily incident to a vertex already in the tree, and that do not
form a circuit, are chosen.

Minimum Spanning Trees 15


Example of Kruskal’s Algorithm, Step 1 of 4

a 2 b 3 c 1 d
edge $
edge $
{b, f } 1
{g , h} 3
3 1 2 5 {c, d} 1
{h, l } 3
4 f 3 g 3 {k, l} 1
e h {i , j} 3
{a, b} 2
{j, k} 3
{c, g } 2
4 2 4 3 {e, f } 4
{f , j} 2
3 3 1 {e, i } 4
{a, e} 3
{g , k} 4
i j k l {b, c} 3
{d, h} 5
{f , g } 3
List of edges of G sorted by weight.

Minimum Spanning Trees 16


Example of Kruskal’s Algorithm, Step 2 of 4

a 2 b 3 c 1 d
edge $
edge $
{b, f } 1
3 1 2 5 {g , h} 3
{c, d} 1
4 f 3 g 3 {h, l } 3
e h {k, l } 1
{i , j} 3
{a, b} 2 {j, k} 3
4 2 4 3 {c, g } 2
{e, f } 4
3 3 1 {f , j} 2
{e, i } 4
{a, e} 3
i j k l {g , k} 4
{b, c} 3
{d, h} 5
Add the edges {b, f }, {c, d} and {f , g } 3
{k, l }.

Minimum Spanning Trees 17


Example of Kruskal’s Algorithm, Step 3 of 4

a 2 b 3 c 1 d
edge $
edge $
{b, f } 1
3 1 2 5 {g , h} 3
{c, d} 1
4 f 3 g 3 {h, l } 3
e h {k, l } 1
{a, b} 2 {i , j} 3
{j, k} 3
4 2 4 3 {c, g } 2
{e, f } 4
3 3 1 {f , j} 2
{e, i } 4
{a, e} 3
i j k l {g , k} 4
{b, c} 3
{d, h} 5
Add the edges {a, b}, {c, g } and {f , g } 3
{f , j}.

Minimum Spanning Trees 18


Example of Kruskal’s Algorithm, Step 4 of 4

a 2 b 3 c 1 d

edge $
3 1 2 5 edge $
{b, f } 1
4 f 3 g 3 {g , h} 3
e h {c, d} 1
{h, l } 3
{k, l } 1
{i , j} 3
4 2 4 3 {a, b} 2
{c, g } 2 {j, k} 3
3 3 1
{f , j} 2 {e, f } 4
i j k l {a, e} 3 {e, i } 4
{g , k} 4
Add the edges {a, e}, {b, c}, {g , h}, {b, c} 3
{d, h} 5
{h, l } and {i , j}. The edge {f , g } {f , g } 3
was not added because it forms a
circuit.

Minimum Spanning Trees 19


Example of Kruskal’s Algorithm

a 2 b 3 c 1 d edge $
{b, f } 1 edge $
{c, d} 1 {g , h} 3
3 1 2 {h, l } 3
f g 3 {k, l } 1
e h {i , j} 3
{a, b} 2
{j, k} 3
{c, g } 2
2 {e, f } 4
{f , j} 2
3 3 1 {e, i } 4
{a, e} 3
{g , k} 4
i j k l {b, c} 3
{d, h} 5
Final solution. {f , g } 3

Minimum Spanning Trees 20

You might also like