SlideShare a Scribd company logo
KRUSKAL’S
ALGORITHM
DETAILED ANALYSIS ON:
JOSEPH KRUSKAL
• JOSEPH KRUSKAL WAS AN AMERICAN MATHEMATICIAN, STATISTICIAN AND
COMPUTER SCIENTIST.
• HE WAS BORN IN JANUARY 29, 1928.
• HE WAS A STUDENT AT THE UNIVERSITY OF CHICAGO EARNING A BACHELOR OF
SCIENCE IN MATHEMATICS IN THE YEAR OF 1948 AND A MASTER OF SCIENCE IN
MATHEMATICS IN THE FOLLOWING YEAR 1949.
• AFTER HIS TIME AT THE UNIVERSITY OF CHICAGO, KRUSKAL ATTENDED PRINCETON
UNIVERSITY, WHERE HE COMPLETED HIS PH.D. IN MATHEMATICS IN THE YEAR OF 1954.
• IN STATISTICS, KRUSKAL'S MOST INFLUENTIAL WORK IS HIS SEMINAL CONTRIBUTION TO THE
FORMULATION OF MULTIDIMENSIONAL SCALING.
• IN COMPUTER SCIENCE, HIS BEST KNOWN WORK IS KRUSKAL'S ALGORITHM FOR COMPUTING
THE MINIMAL SPANNING TREE (MST) OF A WEIGHTED GRAPH.
• HE DIED IN SEPTEMBER 19, 2010.
WHAT IS AN ALGORITHM?
AN ALGORITHM IS A STEP-BY-STEP
PROCEDURE TO SOLVE A GIVEN
PROBLEM.
KRUSKAL'S ALGORITHM IS AN ALGORITHM
FOR
COMPUTING THE MINIMAL SPANNING
TREE (MST)
OF A WEIGHTED GRAPH.
KRUSKAL’S ALGORITHM
A Minimal Spanning Tree is a Spanning Tree of
a connected, undirected graph which connects
all the vertices together with the Minimal total
weightage for its edges and it always have V-1
Edges.
A
B
C
D
1 3
2
KRUSKAL'S ALGORITHM IS AN ALGORITHM
FOR
COMPUTING THE MINIMAL SPANNING
TREE (MST)
OF A WEIGHTED GRAPH.
KRUSKAL’S ALGORITHM
A weighted graph is a graph
whose vertices or edges
have been assigned weights.
A
B
C
D
1 3
2
2
5
LETS SEE A GRAPH…!
A
B
C
D
1 3
2
2
5
Vertices
Edge
Weight of an
Edge
HOW TO FIND MINIMAL SPANNING TREE (MST) BY USING
KRUSKAL’S ALGORITHM?
We will always start from the
smallest weight edge and keep
selecting edges that does not
form any circuit with the
previously selected edges.
REMEMBER…
.
A
B
C
D
1 3
2
2
5
We will always start from the smallest weight edge and keep selecting edges
that does not form any circuit with the previously selected edges.
We have 5 edges.
So our edge table will have 5 columns.
Create the edge table.
(An edge table will have name
of all the edges along with their
weight in ascending order)
Edge
Weight
STEPS TO FIND MINIMAL SPANNING TREE (MST) BY USING
KRUSKAL’S ALGORITHM
A
B
C
D
1 3
2
2
5
We will always start from the smallest weight edge and keep selecting edges
that does not form any circuit with the previously selected edges.
Edge
Weight
Now look at the graph and fill the
1st column with the edge of minimum weight.
In this case edge BC is of least weight
so we will select it.
BC
1
Now look at the graph again and find the
edge of next minimum weight.
In this case edge AB and AC are having
the minimum weight so we will select
them both.
Note!
In case we have two or more
edges with same weight then
we can write them in any order
in the edge table.
AB
2
AC
2
A
B
C
D
1 3
2
2
5
We will always start from the smallest weight edge and keep selecting edges
that does not form any circuit with the previously selected edges.
Edge
Weight
BC
1
Now look at the graph again and find the
edge of next minimum weight.
In this case edge AB and AC are having
the minimum weight so we will select
them both.
Note!
In case we have two or more
edges with same weight then
we can write them in any order
in the edge table.
AB
2
AC
2
A
B
C
D
1 3
2
2
5
We will always start from the smallest weight edge and keep selecting edges
that does not form any circuit with the previously selected edges.
Edge
Weight
BC
1
AB
2
AC
2
Now look at the graph again and
find the edge of next minimum edge.
In this case edge DC has the
minimum weight so we will select it.
DC
2
Now look at the graph again
and find the edge of next
minimum edge.
In this case edge BD has the
minimum weight so we will
select it.
BD
5
A
B
C
D
1 3
2
2
5
We will always start from the smallest weight edge and keep selecting edges
that does not form any circuit with the previously selected edges.
TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING
KRUSKAL’S ALGORITHM
Edge
Weight
BC
1
AB
2
AC
2
DC
2
BD
5
Note! Our graph has 4 vertices.
So, our MST will have 3 edges.
We will always start from the smallest weight edge and keep selecting edges
that does not form any circuit with the previously selected edges.
TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING
KRUSKAL’S ALGORITHM
Edge
Weight
BC
1
AB
2
AC
2
DC
2
BD
5
1 is the smallest weight.
So we will select edge BC.
B
C
1
A
B
C
D
1 3
2
2
5
A
2
A
B
C
D
1 3
2
2
5
We will always start from the smallest weight edge and keep selecting edges
that does not form any circuit with the previously selected edges.
TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING
KRUSKAL’S ALGORITHM
Edge
Weight
BC
1
AB
2
AC
2
DC
2
BD
5
2 is the next smallest
weight and edge AB does
not form a circuit with the
previously selected edges.
So we will select it.
B
C
1
A
2
A
B
C
D
1 3
2
2
5
We will always start from the smallest weight edge and keep selecting edges
that does not form any circuit with the previously selected edges.
TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING
KRUSKAL’S ALGORITHM
Edge
Weight
BC
1
AB
2
AC
2
DC
2
BD
5
2 is the smallest weight.
But if we select edge AC
then it will form a circuit. So
we are going to reject edge AC.
B
C
1
D
3
A
2
A
B
C
D
1 3
2
2
5
We will always start from the smallest weight edge and keep selecting edges
that does not form any circuit with the previously selected edges.
TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING
KRUSKAL’S ALGORITHM
Edge
Weight
BC
1
AB
2
AC
2
DC
2
BD
5
3 is the next smallest weight and
edge DC does not form a circuit
with the previously selected edges.
So we will select it.
B
C
1
D
3
A
2
A
B
C
D
1 3
2
2
5
We will always start from the smallest weight edge and keep selecting edges
that does not form any circuit with the previously selected edges.
TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING
KRUSKAL’S ALGORITHM
Edge
Weight
BC
1
AB
2
AC
2
DC
2
BD
5
3 is the next smallest weight and
edge DC does not form a circuit
with the previously selected edges.
So we will select it.
B
C
1
D
3
A
2
A
B
C
D
1 3
2
2
5
We will always start from the smallest weight edge and keep selecting edges
that does not form any circuit with the previously selected edges.
TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING
KRUSKAL’S ALGORITHM
Edge
Weight
BC
1
AB
2
AC
2
DC
2
BD
5
B
C
1
Since we have got the 3 edges.
So we will stop here.
THEREFORE, OUR REQUIRED MINIMUM SPANNING TREE IS
D
3
A
2
B
C
1
Below are the steps for finding MST using Kruskal’s algorithm:
#Sort all the edges in non-decreasing order of their weight.
#Pick the smallest edge.
#Check if it forms a cycle with the spanning tree formed so far.
#If the cycle is not formed, include this edge.
Else, discard it.
#Repeat step#2 until there are (V-1) edges in the spanning tree.
KRUSKAL’S ALGORITHM IMPLEMENTATION IN CODE
 Make_Set(V) will try to think each vertices a individual tree
 Find_Set is the function that checks the other vertices that are reachable
 Find_Set is a trick to check whether it will create a cycle or not
 UNION merges two trees
KRUSKAL’S ALGORITHM IMPLEMENTATION IN CODE
TIME COMPLEXITY FOR GRAPH
 For Graph G=(V,E)
 For Most Efficient Time Complexity here, we use either Merge or Heap Sort
 Where time complexity is O(n log n)
 Thus, For this Graph
Time Complexity using Kruskal’s Algorithm is O(E log E) or O(E log V)
MST-KRUSKAL(G, w)
1 A = ∅
2 for each vertex v G.V
∈
3 MAKE-SET(v)
4 sort the edges of G.E into nondecreasing order by weight w
5 for each edge (u, v) G.E, taken in nondecreasing order by weight
∈
6 if FIND-SET(u) ≠ FIND-SET(v)
7 A = A {(u, v)}
∪
8 UNION(u, v)
9 return A
THANK YOU…..

More Related Content

PPTX
Kruskal’s algorithm
PPTX
Kruskal Algorithm for minimum spanning..
PPTX
Kruskal's Algorithm finds a minimum spanning tree.
PPTX
Data structure
PPTX
DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM
PDF
OTP, Phishing, QR code, Shares, Visual Cryptography.
PDF
Ijciras1101
PPT
Krusadfafadfadfafdasdfasdfaasdfasdcsdkal.ppt
Kruskal’s algorithm
Kruskal Algorithm for minimum spanning..
Kruskal's Algorithm finds a minimum spanning tree.
Data structure
DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM
OTP, Phishing, QR code, Shares, Visual Cryptography.
Ijciras1101
Krusadfafadfadfafdasdfasdfaasdfasdcsdkal.ppt

Similar to Kruskal’s Algorithm: Finding the Minimum Spanning Tree (20)

PDF
Minimum Spanning Tree in design and analysis
PDF
19 Minimum Spanning Trees
PPT
Greedy Approach in Design Analysis and Algorithms
PPTX
kruskal and prims algorithm _
PPTX
Data Structures and Algorithms Kruskals algorithm
PPTX
Minimum spanning tree.pptx data structure programming
PPTX
Minimum Spinning Tree Full Explaination pptx
PDF
lecture 23 algorithm design and analysis
PPTX
MSadfadsfafdadfccadradfT_Presentation.pptx
PPTX
Minimum Spanning Tree using Kruskal's Algorithm
PPTX
_A C program for Prim's Minimum Spanning Tree (MST) algorithm. The program is...
PPT
minimum spanning trees Algorithm
PPTX
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
PPTX
Greedy Strategy.pptxbfasjbjfn asnfn anjn
PDF
Unit3_1.pdf
PDF
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
PPTX
Kruskal algorithm
PPTX
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
PDF
DATA STRUCTURES & ALGORITHMS MINIMUM SPANNING TREE
Minimum Spanning Tree in design and analysis
19 Minimum Spanning Trees
Greedy Approach in Design Analysis and Algorithms
kruskal and prims algorithm _
Data Structures and Algorithms Kruskals algorithm
Minimum spanning tree.pptx data structure programming
Minimum Spinning Tree Full Explaination pptx
lecture 23 algorithm design and analysis
MSadfadsfafdadfccadradfT_Presentation.pptx
Minimum Spanning Tree using Kruskal's Algorithm
_A C program for Prim's Minimum Spanning Tree (MST) algorithm. The program is...
minimum spanning trees Algorithm
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
Greedy Strategy.pptxbfasjbjfn asnfn anjn
Unit3_1.pdf
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Kruskal algorithm
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
DATA STRUCTURES & ALGORITHMS MINIMUM SPANNING TREE
Ad

Recently uploaded (20)

PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
additive manufacturing of ss316l using mig welding
PPTX
UNIT 4 Total Quality Management .pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
PPT on Performance Review to get promotions
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Geodesy 1.pptx...............................................
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Well-logging-methods_new................
PPTX
Welding lecture in detail for understanding
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
DOCX
573137875-Attendance-Management-System-original
Internet of Things (IOT) - A guide to understanding
Lecture Notes Electrical Wiring System Components
Automation-in-Manufacturing-Chapter-Introduction.pdf
additive manufacturing of ss316l using mig welding
UNIT 4 Total Quality Management .pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPT on Performance Review to get promotions
Mechanical Engineering MATERIALS Selection
Geodesy 1.pptx...............................................
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
CH1 Production IntroductoryConcepts.pptx
Well-logging-methods_new................
Welding lecture in detail for understanding
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Operating System & Kernel Study Guide-1 - converted.pdf
R24 SURVEYING LAB MANUAL for civil enggi
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
573137875-Attendance-Management-System-original
Ad

Kruskal’s Algorithm: Finding the Minimum Spanning Tree

  • 2. JOSEPH KRUSKAL • JOSEPH KRUSKAL WAS AN AMERICAN MATHEMATICIAN, STATISTICIAN AND COMPUTER SCIENTIST. • HE WAS BORN IN JANUARY 29, 1928. • HE WAS A STUDENT AT THE UNIVERSITY OF CHICAGO EARNING A BACHELOR OF SCIENCE IN MATHEMATICS IN THE YEAR OF 1948 AND A MASTER OF SCIENCE IN MATHEMATICS IN THE FOLLOWING YEAR 1949. • AFTER HIS TIME AT THE UNIVERSITY OF CHICAGO, KRUSKAL ATTENDED PRINCETON UNIVERSITY, WHERE HE COMPLETED HIS PH.D. IN MATHEMATICS IN THE YEAR OF 1954. • IN STATISTICS, KRUSKAL'S MOST INFLUENTIAL WORK IS HIS SEMINAL CONTRIBUTION TO THE FORMULATION OF MULTIDIMENSIONAL SCALING. • IN COMPUTER SCIENCE, HIS BEST KNOWN WORK IS KRUSKAL'S ALGORITHM FOR COMPUTING THE MINIMAL SPANNING TREE (MST) OF A WEIGHTED GRAPH. • HE DIED IN SEPTEMBER 19, 2010.
  • 3. WHAT IS AN ALGORITHM? AN ALGORITHM IS A STEP-BY-STEP PROCEDURE TO SOLVE A GIVEN PROBLEM.
  • 4. KRUSKAL'S ALGORITHM IS AN ALGORITHM FOR COMPUTING THE MINIMAL SPANNING TREE (MST) OF A WEIGHTED GRAPH. KRUSKAL’S ALGORITHM A Minimal Spanning Tree is a Spanning Tree of a connected, undirected graph which connects all the vertices together with the Minimal total weightage for its edges and it always have V-1 Edges. A B C D 1 3 2
  • 5. KRUSKAL'S ALGORITHM IS AN ALGORITHM FOR COMPUTING THE MINIMAL SPANNING TREE (MST) OF A WEIGHTED GRAPH. KRUSKAL’S ALGORITHM A weighted graph is a graph whose vertices or edges have been assigned weights. A B C D 1 3 2 2 5
  • 6. LETS SEE A GRAPH…! A B C D 1 3 2 2 5 Vertices Edge Weight of an Edge
  • 7. HOW TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM? We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges. REMEMBER… .
  • 8. A B C D 1 3 2 2 5 We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges. We have 5 edges. So our edge table will have 5 columns. Create the edge table. (An edge table will have name of all the edges along with their weight in ascending order) Edge Weight STEPS TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM
  • 9. A B C D 1 3 2 2 5 We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges. Edge Weight Now look at the graph and fill the 1st column with the edge of minimum weight. In this case edge BC is of least weight so we will select it. BC 1 Now look at the graph again and find the edge of next minimum weight. In this case edge AB and AC are having the minimum weight so we will select them both. Note! In case we have two or more edges with same weight then we can write them in any order in the edge table. AB 2 AC 2
  • 10. A B C D 1 3 2 2 5 We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges. Edge Weight BC 1 Now look at the graph again and find the edge of next minimum weight. In this case edge AB and AC are having the minimum weight so we will select them both. Note! In case we have two or more edges with same weight then we can write them in any order in the edge table. AB 2 AC 2
  • 11. A B C D 1 3 2 2 5 We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges. Edge Weight BC 1 AB 2 AC 2 Now look at the graph again and find the edge of next minimum edge. In this case edge DC has the minimum weight so we will select it. DC 2 Now look at the graph again and find the edge of next minimum edge. In this case edge BD has the minimum weight so we will select it. BD 5
  • 12. A B C D 1 3 2 2 5 We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges. TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM Edge Weight BC 1 AB 2 AC 2 DC 2 BD 5 Note! Our graph has 4 vertices. So, our MST will have 3 edges.
  • 13. We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges. TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM Edge Weight BC 1 AB 2 AC 2 DC 2 BD 5 1 is the smallest weight. So we will select edge BC. B C 1 A B C D 1 3 2 2 5
  • 14. A 2 A B C D 1 3 2 2 5 We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges. TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM Edge Weight BC 1 AB 2 AC 2 DC 2 BD 5 2 is the next smallest weight and edge AB does not form a circuit with the previously selected edges. So we will select it. B C 1
  • 15. A 2 A B C D 1 3 2 2 5 We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges. TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM Edge Weight BC 1 AB 2 AC 2 DC 2 BD 5 2 is the smallest weight. But if we select edge AC then it will form a circuit. So we are going to reject edge AC. B C 1
  • 16. D 3 A 2 A B C D 1 3 2 2 5 We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges. TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM Edge Weight BC 1 AB 2 AC 2 DC 2 BD 5 3 is the next smallest weight and edge DC does not form a circuit with the previously selected edges. So we will select it. B C 1
  • 17. D 3 A 2 A B C D 1 3 2 2 5 We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges. TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM Edge Weight BC 1 AB 2 AC 2 DC 2 BD 5 3 is the next smallest weight and edge DC does not form a circuit with the previously selected edges. So we will select it. B C 1
  • 18. D 3 A 2 A B C D 1 3 2 2 5 We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges. TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM Edge Weight BC 1 AB 2 AC 2 DC 2 BD 5 B C 1 Since we have got the 3 edges. So we will stop here.
  • 19. THEREFORE, OUR REQUIRED MINIMUM SPANNING TREE IS D 3 A 2 B C 1
  • 20. Below are the steps for finding MST using Kruskal’s algorithm: #Sort all the edges in non-decreasing order of their weight. #Pick the smallest edge. #Check if it forms a cycle with the spanning tree formed so far. #If the cycle is not formed, include this edge. Else, discard it. #Repeat step#2 until there are (V-1) edges in the spanning tree. KRUSKAL’S ALGORITHM IMPLEMENTATION IN CODE
  • 21.  Make_Set(V) will try to think each vertices a individual tree  Find_Set is the function that checks the other vertices that are reachable  Find_Set is a trick to check whether it will create a cycle or not  UNION merges two trees KRUSKAL’S ALGORITHM IMPLEMENTATION IN CODE
  • 22. TIME COMPLEXITY FOR GRAPH  For Graph G=(V,E)  For Most Efficient Time Complexity here, we use either Merge or Heap Sort  Where time complexity is O(n log n)  Thus, For this Graph Time Complexity using Kruskal’s Algorithm is O(E log E) or O(E log V) MST-KRUSKAL(G, w) 1 A = ∅ 2 for each vertex v G.V ∈ 3 MAKE-SET(v) 4 sort the edges of G.E into nondecreasing order by weight w 5 for each edge (u, v) G.E, taken in nondecreasing order by weight ∈ 6 if FIND-SET(u) ≠ FIND-SET(v) 7 A = A {(u, v)} ∪ 8 UNION(u, v) 9 return A