Unit 5 Session 3 Kruskals
Unit 5 Session 3 Kruskals
M SCIENCE AND
INSTITUTE OF
TECHNOLOGY,
CHENNAI.
18CSC201J
DATA STRUCTURES AND ALGORITHMS
Unit- V
SR
M AND TECHNOLOGY,
INSTITUTE OF SCIENCE
CHENNAI.
The cost of the spanning tree is the sum of the weights of all the
edges in the tree. There can be many spanning trees. Minimum
spanning tree is the spanning tree where the cost is minimum among
all the spanning trees. There also can be many minimum spanning
trees.
Minimum Spanning Tree
Minimum spanning tree has direct application in the design of
networks. It is used in algorithms approximating the travelling
salesman problem, multi-terminal minimum cut problem and
minimum-cost weighted perfect matching. Other practical
applications are:
1.Cluster Analysis
2.Handwriting recognition
3.Image segmentation
Kruskal’s Algorithm
3 4
2 3 4
4 5
2
9
5 6
1
1
12
8 10
7 8 9
7
The graph contains 9 vertices and 11 edges. So, the minimum spanning
tree formed will be having (9 – 1) = 8 edges.
Sort the weights of the graph
Weight Source Destination
1 8 5
2 3 5
3 2 3
4 1 2
4 3 4
5 4 6
7 7 8
8 1 7
9 5 6
10 8 9
12 9 6
Now pick all edges one by one from sorted list of edges
5
Weigh
t
Source Destina
tion 1
1 8 5
8
2 3 5
3 2 3
4 1 2
4 3 4
5 4 6
7 7 8
8 1 7
9 5 6
10 8 9
12 9 6
3
2
5
1 8 5 8
2 3 5
3 2 3
4 1 2
4 3 4
5 4 6
7 7 8
8 1 7
9 5 6
10 8 9
12 9 6
3
2 3
2
5
Weigh Source Destina
t tion
1
1 8 5
2 3 5 8
3 2 3
4 1 2
4 3 4
5 4 6
7 7 8
8 1 7
9 5 6
10 8 9
12 9 6
3
2 3
4
2
1 5
Weigh Source Destina
t tion 1
1 8 5
2 3 5 8
3 2 3
4 1 2
4 3 4
5 4 6
7 7 8
8 1 7
9 5 6
10 8 9
12 9 6
3 4
2 3 4
4
2
1 5
Weigh Source Destina
t tion 1
1 8 5
2 3 5
8
3 2 3
4 1 2
4 3 4
5 4 6
7 7 8
8 1 7
9 5 6
10 8 9
12 9 6
3 4
2 3 4
5
4
2
6
1 5
1
Weigh Source Destina
t tion 8
1 8 5
2 3 5
3 2 3
4 1 2
4 3 4
5 4 6
7 7 8
8 1 7
9 5 6
10 8 9
12 9 6
3 4
2 3 4
5
4
2
6
1 5
1
Weigh Source Destina
t tion 7 8
7
1 8 5
2 3 5
3 2 3
4 1 2
4 3 4
5 4 6
7 7 8
8 1 7
9 5 6
10 8 9
12 9 6
3
2 3 4
5
4 4
2
6
1 5
1
Weigh Source Destina 8
t tion
7 8
1 8 5 7
2 3 5
3 2 3
4 1 2
4 3 4 Cycle is formed because of weight 8. hence it is discarded
5 4 6
7 7 8
8 1 7
9 5 6
10 8 9
12 9 6
3 4
2 3 4
5
4
2
9 6
1 5
1
7 8
Weigh Source Destina 7
t tion
1 8 5
2 3 5
3 2 3
4 1 2
4 3 4 Cycle is formed because of weight 9. hence it is discarded.
5 4 6
7 7 8
8 1 7
9 5 6
10 8 9
12 9 6
3 4
2 3 4
5
4
2
6
1 5
1
10
7 8 9
7
Weigh Source Destina
t tion
1 8 5
2 3 5
3 2 3
4 1 2
4 3 4 Cycle is formed because of weight 12. hence it is discarded.
5 4 6
7 7 8
8 1 7
9 5 6
10 8 9
12 9 6
3 4
2 3 4
5
4
2
6
1 5
1
12
10
7 8 9
7
Weigh Source Destina
t tion
1 8 5
2 3 5
3 2 3
4 1 2
4 3 4 Cycle is formed because of weight 12. hence it is discarded.
5 4 6
7 7 8
8 1 7
9 5 6
10 8 9
12 9 6
3 4
2 3 4
5
4
2
6
1 5
1
10
7 8 9
7