You are on page 1of 48

Minimum Spanning Tree

Chapter-6

Objectives
To Study Spanning Tree To Study Minimal Spanning Tree To Study Algorithm for construction of Minimal Spanning Tree Kruskals Algorithm Prims Algorithm

Example of a Problem that Translates into a MST


The Problem Several pins of an electronic circuit must be connected using the least amount of wire.

Modeling the Problem The graph is a complete, undirected graph G = ( V, E ,W ), where V is the set of pins, E is the set of all possible interconnections between the pairs of pins and w(e) is the length of the wire needed to connect the pair of vertices. Find a minimum spanning tree.

Spanning Tree
A spanning tree is a sub graph of a graph. It is a tree containing all the nodes of the graph. If we append any edge into the spanning tree, then a cycle is formed.

Spanning trees
Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges do not have an associated direction ...then a spanning tree of the graph is a connected subgraph in which there are no cycles

A connected, undirected graph

Four of the spanning trees of the graph

Spanning Tree

Undirected graph and 3 of its spanning trees

Spanning Trees Undirected Graph

Minimizing costs
Suppose you want to supply a set of houses (say, in a new subdivision) with:
electric power water sewage lines telephone lines

To keep costs down, you could connect these houses with a spanning tree (of, for example, power lines)
However, the houses are not all equal distances apart

To reduce costs even further, you could connect the houses with a minimum-cost spanning tree

Minimum-cost spanning trees


Suppose you have a connected undirected graph with a weight (or cost) associated with each edge The cost of a spanning tree would be the sum of the costs of its edges A minimum-cost spanning tree is that spanning tree that has the lowest cost
A
19 16 21 11

B
5

16 11

B
5

33

F
18

14

C
10

F
E
18

A connected, undirected graph

A minimum-cost spanning tree

Minimal Spanning Tree


E.g.: To connect the cities via communication link so that the cost of the project is minimum i.e. the length of the links should be minimum.

A Spanning tree with minimum cost is known as

minimal spanning tree.

Applications of Spanning Trees


Minimal path routing in all kinds of settings
circuits, networks, roads and sewers

Minimal Spanning Tree


Two algorithms to construct Minimal Spanning Tree: Kruskals Algorithm Prims Algorithm

Kruskals Algorithm
To find the minimal spanning tree Step 1: Lengths of the graph are arranged in ascending order

Step 2: The first edge is included in the spanning tree

Step 3: The next edge to be included is (1,4)

Step 4: Now, include edge (6,7)

Step 5: The next edge to be included is (1,3)

Step 6: Now, include edge (2, 5)

Step 7: By including (2, 3) it forms a cycle. So it is rejected

Step 8: Now include edge (5, 6) in the minimal spanning tree

Step 9: Edges (1, 2), (4, 5), (4, 6) & (5, 7) forms cycle. So they are rejected

Step 10: This is the final Minimal Spanning Tree.

Prims Algorithm
To find the Minimal Spanning Tree

starting with a tree consisting of a single vertex,


The tree is constructed by choosing a sequence of edges.

Step 1: Include the smallest edge in the tree

Step 2: We have to include the edges whose one vertex is already in the tree And other vertex is new. So we can include (1, 3), (2, 3), (2, 5), (4, 5), (5, 6) or (5, 7)

Step 3: So, we will insert edge (1, 3) as its length is minimum.

Step 4: Now, we can insert (1, 4), (1, 2), (2, 3), (2, 5), (4, 5), (5, 6) or (5, 7)

Step 5: So insert edge (1, 4) in the minimal spanning tree

Step 6: Next insert edge (2, 5)

Step 7: By including (2, 3) it forms a cycle. So we insert edge (5, 6)

Step 8: Next insert edge (6, 7) This is the Final Minimal Spanning Tree

Prims algorithm
1
10 6 25 24 5 18 22 12

28
2 14 7 16 3 10

1
2

6
5

Prims algorithm
1
10 6 25 24 5 18 22 12

28
2 14 7 16 3 10

1
2

6
25 5

Prims algorithm
1
10 6 25 24 5 18 22 12

28
2 14 7 16 3 10

1
2

6
25 5

22
4

Prims algorithm
1
10 6 25 24 5 18 22 12

28
2 14 7 16 3 10

1
2

6
25 5

3
12 4

22

Prims algorithm
1
10 6 25 24 5 18 22 12

28
2 14 7 16 3 10

1
2 16

6
25 5

3
12 4

22

Prims algorithm
1
10 6 25 24 5 18 22 12

28
2 14 7 16 3 10

1
2 14 16

6
25 5

3
12 4

22
Cost = 99

Kruskals Algorithm
5

A
1 B 8 9

E 2

7 D 5 F

{A,B}

1 2 5 5 7 8 9 12

{A,D} {A,E} {D,F} {E,D} {B,C} {B,D} {C,D}

12
C

A B C

E D F

Kruskals Algorithm
{A,B} {A,D}
A 1 B C F E D

1 2 5 5 7 8 9 12

{A,E}

{D,F} {E,D} {B,C} {B,D} {C,D}

Kruskals Algorithm
{A,B} {A,D}
A 1 B C F E 2

1 2 5 5 7 8 9 12

{A,E}
D

{D,F} {E,D} {B,C} {B,D} {C,D}

Kruskals Algorithm
{A,B} {A,D}
5 A 1 B C F E 2

1 2 5 5 7 8 9 12

{A,E}
D

{D,F} {E,D} {B,C} {B,D} {C,D}

Kruskals Algorithm
{A,B} {A,D}
5 A 1 B C E 2

1 2 5 5 7 8 9 12

{A,E}
D 5 F

{D,F} {E,D} {B,C} {B,D} {C,D}

Kruskals Algorithm
{A,B} {A,D}
5 A 1 B C E 2

1 2 5 5 7 8 9 12

{A,E}
D 5 F

{D,F} {E,D} {B,C} {B,D} {C,D}

{E,D} will create a cycle

Kruskals Algorithm
{A,B} {A,D}
5 A 1 B E 2

1 2 5 5 7 8 9 12

{A,E}
D 5 F

{D,F} {E,D} {B,C} {B,D} {C,D}

Kruskals Algorithm
{A,B} {A,D}
5 A 1 B E 2

1 2 5 5 7 8 9 12

{A,E}
D 5 F

{D,F} {E,D} {B,C} {B,D} {C,D}

{B,D} will create a cycle

Kruskals Algorithm
{A,B} {A,D}
5 A 1 B E 2

1 2 5 5 7 8 9 12

{A,E}
D 5 F

{D,F} {E,D} {B,C} {B,D} {C,D}

{C,D} will create a cycle

You might also like