GRAPH ALGORITHMS - MST
GRAPH ALGORITHMS - MST
C D
Directed Graph
Dr. PAVITHRA L K, VIT Chennai 4
A E
C DD
Undirected Graph
Dr. PAVITHRA L K, VIT Chennai 5
Graph G = (V, E )
V – Vertices (nodes)
E – Edges (arcs)
7
5 8
10
Kruskal’s Method
› Take a graph with n vertices.
› Keep on adding shortest edge until (n-1) edges have
been added.
› Insert an edge with the minimum weight.
› Insert edges in increasing order of cost.
› Reject if it forms a cyclic path.
10
D C
2
A B
D C
2
Dr. PAVITHRA L K, VIT Chennai 18
Insert edges in increasing order of weight.
Edge AB have the next minimum weight 4.
4
A B
D C
2
Dr. PAVITHRA L K, VIT Chennai 19
Include the next minimum weight node.
Check the cycles in the tree
4
A B
D C
2
Dr. PAVITHRA L K, VIT Chennai 20
Check the condition e = n -1
e → number of edges
n → number of vertices
If the condition satisfied then stop the process.
The Kruskal’s minimum cost spanning tree will be,
4
A B
D C
2
Dr. PAVITHRA L K, VIT Chennai 21
Step 1: Remove all the loops and parallel edges from
the graph.
Step 2: Choose any arbitrary vertex as root node.
Step 3: Select an edge e1 has the minimum weight
among the edges incident to root node.
Step 4: Follow the step 3for the newly added vertex.
Step 5: Repeat till n-1 edges have been added.
6 D
5
B 3
7
2 E
C
4
Dr. PAVITHRA L K, VIT Chennai 23
A 1
6 D
5
B 3
7
2 E
C
4
Dr. PAVITHRA L K, VIT Chennai 24
A 1
6 D
5
B 3
7
2 E
C
4
Dr. PAVITHRA L K, VIT Chennai 25
A 1
6 D
5
B 3
7
2 E
C
4
Dr. PAVITHRA L K, VIT Chennai 26
A 1
D
6 5
B 3
7
2 E
C
4
Dr. PAVITHRA L K, VIT Chennai 27
A 1
6 D
5
B 3
7
2 E
C
4
Dr. PAVITHRA L K, VIT Chennai 28
y 5 o
4
7
3 q
6 2
x
2
8 z p
3
5 8 4
10
B C
1
10 20 C
20
D 50
E
10
Dr. PAVITHRA L K, VIT Chennai 38
60
A B
50
10 20 C
20
D 50
E
10
Dr. PAVITHRA L K, VIT Chennai 39
A B C D E
X 2 3 9
6
W V
2
3 4 8
4
6
V4 V7
4 3
7
V3 V6
A C
B
D
D
C
A
B
Questions Please..
Dr. PAVITHRA L K, VIT Chennai 50
Dr. PAVITHRA L K, VIT Chennai 51