Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Kruskal’s Algorithm

 Recap of Minimum Spanning Tree


 Kruskal’s Algorithm
 Numerical 1
Index  Numerical 2
 Differences between Prim’s and Kruskal’s Algorithm
 Applications of MST
Recap of Spanning Tree?
Minimum  Given a connected and undirected graph, a spanning
Spanning Tree tree of that graph is a subgraph that is a tree and
connects all the vertices together.
Minimum Spanning Tree?
Recap of  The spanning tree of the graph whose sum of weights
Minimum of edges is minimum.
Spanning Tree  A graph may have more than 1 minimum spanning
tree.
Steps for finding MST using Kruskal’s algorithm
Kruskal’s 1. Sort all the edges in non-decreasing order of their
weight.
Algorithm 2. Pick the smallest edge. Check if it forms a cycle with
(1856, by Joseph
the spanning tree formed so far. If cycle is not
Kruskal)
formed, include this edge. Else, discard it.
3. Repeat step#2 until there are (V-1) edges in the
spanning tree.
B 8
5
6

Numerical 1 A D
Find Minimum spanning
Tree (MST) of the given
undirected edge-weighted 8
graph using Kruskal’s 6
algorithm. 7 8

C 6
E
B 8
5
6

A D

Problem 1 8
6
7 8

C 6
E
Edge AB AC BC BD BE CD CE DE

Wt. 5 6 7 8 6 8 6 8
B 8
5
6

A D

Step 1 8
6
7 8

C 6
E
Edge AB AC BE CE BC BD CD DE

Wt. 5 6 6 6 7 8 8 8
B 8
5
6

A D

Step 2 8
6
7 8

C 6
E
B 8
5
6

A D

Step 3
6
Total Weight = 5+6+6+8
= 25
C E
8 7
Numerical 2 B C D
Find Minimum spanning Tree
4 2 9
(MST) of the given undirected
edge-weighted graph using
Kruskal’s algorithm.
A 11 J 4 14 E
7
8 6 10
H 1 G 2 F

Edge AB BC CD DE EF FG GH HJ BH DF JC JG CF AH
Wt. 4 8 7 9 10 2 1 7 11 14 2 6 4 8
8 7
Step 1 B C D
Sort all the edges in non-
4 2 9
decreasing order of their
weights.
A 11 J 4 14 E
7
8 6 10
H 1 G 2 F

Edge HG JC FG AB CF JG CD HJ AH BC DE EF BH DF
Wt. 1 2 2 4 4 6 7 7 8 8 9 10 11 14
8 7
Step 2 B C D
Pick the smallest edge.
4 2 9
Check if it forms a cycle
with the spanning tree
A 11 J 4 14 E
formed so far.
7
If cycle is not formed,
include this edge. 8 6 10
Else, discard it.
H 1 G 2 F

Edge HG JC FG AB CF JG CD HJ AH BC DE EF BH DF
Wt. 1 2 2 4 4 6 7 7 8 8 9 10 11 14
8 7
Step 3 B C D
Repeat step 2 until there
4 2 9
are (V-1) edges in the
spanning tree.
A 11 J 4 14 E
7
8 6 10
H 1 G 2 F

Edge HG JC FG AB CF JG CD HJ AH BC DE EF BH DF
Wt. 1 2 2 4 4 6 7 7 8 8 9 10 11 14
8 7
Step 3 B C D
Repeat step 2 until there
4 2 9
are (V-1) edges in the
spanning tree.
A 11 J 4 14 E
In this problem, we have 9
nodes. 7
We terminate the process 8 6 10
of adding edges to the tree
as we have got 9 – 1 = 8
edges. H 1 G 2 F

Edge HG JC FG AB CF JG CD HJ AH BC DE EF BH DF
Wt. 1 2 2 4 4 6 7 7 8 8 9 10 11 14
7
Answer B C D
Weight of the Minimum
4 2 9
Spanning Tree
=1+ 2 + 2 + 4 + 4 + 7 + 8 + 9
= 37
A J 4 E

8
H 1 G 2 F

Edge HG JC FG AB CF JG CD HJ AH BC DE EF BH DF
Wt. 1 2 2 4 4 6 7 7 8 8 9 10 11 14
BASIS FOR
PRIM’S ALGORITHM KRUSKAL’S ALGORITHM
COMPARISON
The algorithm obtains the minimum To obtain the minimum
spanning tree by choosing the spanning tree this algorithm
Basic
adjacent vertices from a set of select the edges from a set
selected vertices. of edges.
Differences Selection of the
Vertices Edges
Between route is based on
Connected All the graph components must be Disconnected graph may
Prim’s Algorithm components connected. present.
& Speed Better for the dense graph. Good for the sparse graph.
Kruskal’s Algorithm 2
Time complexity O(V ) O(E*log V)

Initiates with A node. An edge.

Selected vertices are not


Adjacent vertices Must be opted for the tree.
necessarily adjacent.
 Network Design
Electric power lines, water pipes, telephone lines, TV
Applications cable, roads
of MST  Computer Network Routing Protocol
 Cluster Analysis
Thanks!

You might also like