SlideShare a Scribd company logo
SRM Institute of Science and Technology
Minimum Spanning Tree -
Kruskal’s Algorithm
SRM Institute of Science and Technology
A Spanning tree can be defined as a subset of a graph, which
consists of all the vertices covering minimum possible edges and
does not have a cycle. Spanning tree cannot be disconnected.
Every connected and undirected graph has at least one spanning
tree. A disconnected graph does not have a spanning tree as it is
not possible to include all vertices.
NN-2 number of spanning trees. Thus in the above graph N =3, therefore, it
has 3(3-2) = 3 spanning trees.
SRM Institute of Science and Technology
Some of the properties of the spanning tree are listed below:
•A connected graph can have more than one spanning trees.
•All spanning trees in a graph have the same number of nodes and
edges.
•If we remove one edge from the spanning tree, then it will
become minimally connected and will make the graph
disconnected.
•On the other hand, adding one edge to the spanning tree will make
it maximally acyclic thereby creating a loop.
•A spanning tree does not have a loop or a cycle.
SRM Institute of Science and Technology
What Is A Minimum Spanning Tree (MST)
A minimum spanning tree is the one that contains the least weight
among all the other spanning trees of a connected weighted graph.
There can be more than one minimum spanning tree for a graph.
•Kruskal’s algorithm
•Prim’s algorithm
SRM Institute of Science and Technology
Minimum Spanning Tree -
Kruskal’s Algorithm
SRM Institute of Science and Technology
•Kruskal’s Algorithm is a famous greedy algorithm.
•It is used for finding the Minimum Spanning Tree (MST) of a given graph.
•To apply Kruskal’s algorithm, the given graph must be weighted, connected and undirected.
Kruskal’s Algorithm Implementation-
The implementation of Kruskal’s Algorithm is explained in the following steps-
Step-01:
•Sort all the edges from low weight to high weight.
Step-02:
•Take the edge with the lowest weight and use it to connect the vertices of graph.
•If adding an edge creates a cycle, then reject that edge and go for the next least weight edge.
SRM Institute of Science and Technology
Step-03:
•Keep adding edges until all the vertices are connected and a Minimum Spanning Tree
(MST) is obtained.
Step 1:Create a forest in such a way that each graph is a separate tree
Step 2: Create a priority queue Q that contains all the edges of the graph
Step 3: Repeat steps 4 and 5 while Q is NOT EMPTY
Step 4: Remove an edge from Q
Step 5: If the edge obtained in Step 4 connects two different trees, then Add it to
the forest(for combining two trees into one tree).
ELSE
Discard the edge
Step 6: END
Kruskal’s Algorithm
Note: Forest is a
collection of trees
SRM Institute of Science and Technology
Thumb Rule to Remember
The above steps may be reduced to the
following thumb rule-
•Simply draw all the vertices on the
paper.
•Connect these vertices using edges
with minimum weights such that no
cycle gets formed.
MST - Kruskal’s Algorithm
SRM Institute of Science and Technology
PRACTICE PROBLEMS BASED
ON KRUSKAL’S ALGORITHM-
Problem-01:
Construct the minimum spanning tree (MST) for the given graph using
Kruskal’s Algorithm-
Now we need to find the
weight of the minimum
spanning tree
Solution-
To construct MST using Kruskal’s Algorithm,
•Simply draw all the vertices on the paper.
•Connect these vertices using edges with minimum weights such that no cycle gets
formed.-
Step-01:
Draw all the vertices on the
paper as you can see in the Fig
No of edges = 9
SRM Institute of Science and Technology
Write all vertex pair
VERTEX PAIR WEIGHT
(1,6) 10
(1,2) 28
(2,3) 16
(2,7) 14
(3,4) 12
(4,5) 22
(4,7) 18
(5,6) 25
(5,7) 24
SRM Institute of Science and Technology
Vertex pair in ascending order
VERTEX PAIR WEIGHT
(1,6) 10
(3,4) 12
(2,7) 14
(2,3) 16
(4,7) 18
(4,5) 22
(5,7) 24
(5,6) 25
(1,2) 28
SRM Institute of Science and Technology
Step-02:
Step-03:
VERTEX PAIR WEIGHT ACTION
(1,6) 10 Accepte
d
(3,4) 12 Accepte
d
(2,7) 14
(2,3) 16
(4,7) 18
(4,5) 22
(5,7) 24
(5,6) 25
(1,2) 28
Accept the edge if it does not form cycle continue till
all nodes are visited
Mark 1 if visited the nodes
No cycle formation
No cycle formation
VERTEX KNOWN
1 1
2 0
3 1
4 1
5 0
6 1
7 0
SRM Institute of Science and Technology
Step-04:
Step-05:
VERTEX PAIR WEIGHT ACTION
(1,6) 10 Accepted
(3,4) 12 Accepted
(2,7) 14 Accepted
(2,3) 16 Accepted
(4,7) 18 Rejected
(4,5) 22
(5,7) 24
(5,6) 25
(1,2) 28
Accept the edge if it does not form cycle
continue till all nodes are visited
VERTEX KNOWN
1 1
2 1
3 1
4 1
5 0
6 1
7 1
Mark 1 if visited the nodes
No cycle
formation
SRM Institute of Science and Technology
Step-06:
Step-07:
Accept the edge if it does not form cycle
continue till all nodes are visited
Since all the vertices have been
connected / included in the MST, so we
stop.
Weight of the MST = Sum of all edge
weights
= 10 + 25 + 22 + 12 + 16 + 14
VERTEX PAIR WEIGHT ACTION
(1,6) 10 Accepted
(3,4) 12 Accepted
(2,7) 14 Accepted
(2,3) 16 Accepted
(4,7) 18 Rejected
(4,5) 22 Accepted
(5,7) 24 Rejected
(5,6) 25 Accepted
(1,2) 28
VERTEX KNOWN
1 1
2 1
3 1
4 1
5 1
6 1
7 1
Mark 1 if visited the nodes
All nodes visited.
Stop the Algorithm
No cycle formation
No cycle formation
SRM Institute of Science and Technology
Problem 2:
Construct the minimum spanning tree (MST) for the given graph using Kruskal’s
Algorithm
Now we need to find the
weight of the minimum
spanning tree
SRM Institute of Science and Technology
V1
V2
V3 V4
V6
V5
Now Let us draw the minimum Spanning Tree using Kruskal’s Algorithm
Draw all the vertices on the
paper as you can see in the Fig
Step 1:
SRM Institute of Science and Technology
Step 2 Step 3
• We shall connect the vertices using
the edges with the least weight
• Now, the least weight edge is 3.So the
vertices V1 and V2 are connected
• Next the least weight edge is 4.So the
vertices V1 and V3 are connected.
No cycle formation.
So accepted. No cycle formation.
So accepted.
SRM Institute of Science and Technology
Step 4
Cycle is not
allowed. So
rejected.
Step 5
• Next least weight edge is 5 which is
connecting V3 and V2.But if we include
this edge, it will contain a cycle which is
not allowed.
• Next the least weight edge is
6.So the vertices V2 and V4 are
connected.
No cycle
formation.
So accepted.
SRM Institute of Science and Technology
Step 6 Step 7
Cycle is not allowed.
So rejected.
• Next least weight edge is 7 which is
connecting V3 and V4.But if we include
this edge, it will contain a cycle which is
not allowed.
No cycle
formation.
So accepted.
• Next the least weight edge is
8.So the vertices V3 and V5 are
connected.
SRM Institute of Science and Technology
Step 8 Step 9
• Next least weight edge is 9 which is
connecting V4 and V5.But if we include
this edge, it will contain a cycle which is
not allowed.
• Next the least weight edge is
10. So the vertices V4 and V6
are connected.
Cycle is not allowed.
So rejected.
No cycle
formation.
So accepted.
SRM Institute of Science and Technology
Step 10 Cycle is not allowed.
So rejected.
• Next least weight edge is 11 which is
connecting V5 and V6.But if we include
this edge, it will contain a cycle which is
not allowed.
Since all the vertices have been connected
/ included in the MST, so we stop.
Weight of the MST = Sum of all edge
weights
= 3 + 4 + 6 + 8 + 10
= 31 units
SRM Institute of Science and Technology
NETWORK FLOW PROBLEM – FORD
FULKERSON ALGORITHM
SRM Institute of Science and Technology
SRM Institute of Science and Technology
Source
S
A B
C D
T
Sink
flow = 0
0/4
0/9
Flow
0/2 0/8 0/6
Initially flow = 0
Source
S
A B
C D
T
Sink
flow = 8
0/4
0/9
Flow
0/2 0/8 0/6
Initially flow = 0
AUGMENTING PATHS
BOTTLE NECK
CAPCITY
S A D T 8
8
8
8
STEP: 1
Minimum capacity
Source
S
A B
C D
T
Sink
flow = 8+2=10
0/4
0/9
Flow
0/2 8/8 0/6
Initially flow = 0
AUGMENTING PATHS
BOTTLE NECK
CAPCITY
2
STEP: 2
Residual capacity
= 10 - 8 =2
2
2
8+2 =10
S C D T
Source
S
A B
C D
T
Sink
flow = 10+4=14
0/4
2/9
Flow
0/2 8/8 0/6
AUGMENTING PATHS BOTTLE NECK CAPCITY
S C D A B T 4
STEP: 3
R capacity = 4
2+4=6
2+4=6
8-4=4
0+4=4
0+4=4
Each and every vertex other than
source and sink should have same
In-flow and Out-flow
Source
S
A B
C D
T
Sink
flow = 14+2=16
4/4
6/9
Flow
0/2 4/8 0/6
AUGMENTING PATHS
BOTTLE NECK
CAPCITY
S A D B T 2
STEP: 4
Same In-flow and Out-flow has to
be maintained
R capacity = 10-8=2
8+2=10
4+2=6 0+2=2
4+2=6
Source
S
A B
C D
T
Sink
flow = 16+3=19
4/4
6/9
Flow
0/2 6/8 2/6
AUGMENTING PATHS
BOTTLE NECK
CAPCITY
S C D B T 3
STEP: 5
R capacity = 9-6=3
6+3=9
6+3=9
2+3=5
6+3=9
Source
S
A B
C D
T
Sink
flow = 16+3=19
4/4
9/9
Flow
0/2 6/8 5/6
AUGMENTING PATHS
BOTTLE NECK
CAPCITY
S C D B T 3
STEP: 6
R capacity = 9-6=3
SRM Institute of Science and Technology
SORTEST PATH ALGORITHM
SRM Institute of Science and Technology
•Shortest path problem is a problem of finding the shortest path(s) between vertices of a
given graph.
•Shortest path between two vertices is a path that has the least cost as compared to all other
existing paths.
Shortest Path Problem-
Shortest Path Algorithms-
Shortest path algorithms are a family of algorithms used for solving the shortest path
problem.
Applications-
•Google Maps
•Road Networks
•Logistics Research
SRM Institute of Science and Technology
Types of Shortest Path Problem-
Various types of shortest path problem are-
Shortest Path Problems
Single Pair Shortest Path Problems
Single Source Shortest Path Problems
Single destination Shortest Path Problems
All Pairs Shortest Path Problems
1.Single-pair shortest path problem
2.Single-source shortest path problem
3.Single-destination shortest path problem
4.All pairs shortest path problem
SRM Institute of Science and Technology
Single-Pair Shortest Path Problem-
•It is a shortest path problem where the shortest path between a given pair of vertices is
computed.
•A* Search Algorithm is a famous algorithm used for solving single-pair shortest path
problem.
Single-Source Shortest Path Problem-
•It is a shortest path problem where the shortest path from a given source vertex to all other
remaining vertices is computed.
•Dijkstra’s Algorithm and Bellman Ford Algorithm are the famous algorithms used for
solving single-source shortest path problem.
SRM Institute of Science and Technology
Single-Destination Shortest Path Problem-
•It is a shortest path problem where the shortest path from all the vertices to a single
destination vertex is computed.
•By reversing the direction of each edge in the graph, this problem reduces to single-source
shortest path problem.
•Dijkstra’s Algorithm is a famous algorithm adapted for solving single-destination shortest
path problem.
All Pairs Shortest Path Problem-
•It is a shortest path problem where the shortest path between every pair of vertices is
computed.
•Floyd-Warshall Algorithm and Johnson’s Algorithm are the famous algorithms used for
solving All pairs shortest path problem.

More Related Content

PPT
KRUSKAL'S algorithm from chaitra
PPTX
Branch And Bound and Beam Search Feature Selection Algorithms
PDF
Machine Learning Algorithm - Decision Trees
PPTX
Binary Search Tree
PPTX
Machine Learning Tutorial Part - 2 | Machine Learning Tutorial For Beginners ...
PPTX
Dimensionality reduction: SVD and its applications
PPTX
Lecture 6 disjoint set
KRUSKAL'S algorithm from chaitra
Branch And Bound and Beam Search Feature Selection Algorithms
Machine Learning Algorithm - Decision Trees
Binary Search Tree
Machine Learning Tutorial Part - 2 | Machine Learning Tutorial For Beginners ...
Dimensionality reduction: SVD and its applications
Lecture 6 disjoint set

What's hot (20)

PPT
minimum spanning tree
PPT
Prim Algorithm and kruskal algorithm
PDF
Matrix chain multiplication
PDF
CSC446: Pattern Recognition (LN7)
PDF
Mean shift and Hierarchical clustering
PPTX
Depth first search [dfs]
PPTX
Bfs and Dfs
PDF
Decision trees in Machine Learning
PPT
Sorting Algorithms
PPTX
PPTX
Minimum spanning tree (mst)
PDF
Binary tree
PPT
Depth First Search ( DFS )
PDF
PRML 9.1-9.2: K-means Clustering & Mixtures of Gaussians
PPT
1.5 binary search tree
PPTX
Minimum spanning Tree
PPTX
Search tree,Tree and binary tree and heap tree
PPTX
PPT
AVL tree animation.ppt
PPTX
Dimensionality Reduction in Machine Learning
minimum spanning tree
Prim Algorithm and kruskal algorithm
Matrix chain multiplication
CSC446: Pattern Recognition (LN7)
Mean shift and Hierarchical clustering
Depth first search [dfs]
Bfs and Dfs
Decision trees in Machine Learning
Sorting Algorithms
Minimum spanning tree (mst)
Binary tree
Depth First Search ( DFS )
PRML 9.1-9.2: K-means Clustering & Mixtures of Gaussians
1.5 binary search tree
Minimum spanning Tree
Search tree,Tree and binary tree and heap tree
AVL tree animation.ppt
Dimensionality Reduction in Machine Learning
Ad

Similar to DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM (20)

PPTX
Data structure
PPT
Greedy Approach in Design Analysis and Algorithms
PPTX
Kruskal’s algorithm
PPTX
Kruskal’s Algorithm: Finding the Minimum Spanning Tree
PDF
OTP, Phishing, QR code, Shares, Visual Cryptography.
PPTX
Data Structures and Algorithms Kruskals algorithm
PDF
Minimum Spanning Tree in design and analysis
PDF
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
PPTX
Minimum spanning tree.pptx data structure programming
PPTX
_A C program for Prim's Minimum Spanning Tree (MST) algorithm. The program is...
PDF
lecture 23 algorithm design and analysis
PPTX
uva-201026072839.pptxvcvczcvzvcxbxcvbcxvbvcxbcx
PPTX
MSadfadsfafdadfccadradfT_Presentation.pptx
PDF
Daa chapter13
PPTX
Kruskal's Algorithm finds a minimum spanning tree.
PPT
Krusadfafadfadfafdasdfasdfaasdfasdcsdkal.ppt
PDF
Ijciras1101
PPTX
Minimum Spinning Tree Full Explaination pptx
PDF
Minimum-Spanning-Tree.pdf ramswaroop memorial University
Data structure
Greedy Approach in Design Analysis and Algorithms
Kruskal’s algorithm
Kruskal’s Algorithm: Finding the Minimum Spanning Tree
OTP, Phishing, QR code, Shares, Visual Cryptography.
Data Structures and Algorithms Kruskals algorithm
Minimum Spanning Tree in design and analysis
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum spanning tree.pptx data structure programming
_A C program for Prim's Minimum Spanning Tree (MST) algorithm. The program is...
lecture 23 algorithm design and analysis
uva-201026072839.pptxvcvczcvzvcxbxcvbcxvbvcxbcx
MSadfadsfafdadfccadradfT_Presentation.pptx
Daa chapter13
Kruskal's Algorithm finds a minimum spanning tree.
Krusadfafadfadfafdasdfasdfaasdfasdcsdkal.ppt
Ijciras1101
Minimum Spinning Tree Full Explaination pptx
Minimum-Spanning-Tree.pdf ramswaroop memorial University
Ad

Recently uploaded (20)

PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
PPT on Performance Review to get promotions
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Welding lecture in detail for understanding
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Well-logging-methods_new................
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPT
Project quality management in manufacturing
PPTX
OOP with Java - Java Introduction (Basics)
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPT on Performance Review to get promotions
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Foundation to blockchain - A guide to Blockchain Tech
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
bas. eng. economics group 4 presentation 1.pptx
Welding lecture in detail for understanding
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Well-logging-methods_new................
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Project quality management in manufacturing
OOP with Java - Java Introduction (Basics)

DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM

  • 1. SRM Institute of Science and Technology Minimum Spanning Tree - Kruskal’s Algorithm
  • 2. SRM Institute of Science and Technology A Spanning tree can be defined as a subset of a graph, which consists of all the vertices covering minimum possible edges and does not have a cycle. Spanning tree cannot be disconnected. Every connected and undirected graph has at least one spanning tree. A disconnected graph does not have a spanning tree as it is not possible to include all vertices.
  • 3. NN-2 number of spanning trees. Thus in the above graph N =3, therefore, it has 3(3-2) = 3 spanning trees.
  • 4. SRM Institute of Science and Technology Some of the properties of the spanning tree are listed below: •A connected graph can have more than one spanning trees. •All spanning trees in a graph have the same number of nodes and edges. •If we remove one edge from the spanning tree, then it will become minimally connected and will make the graph disconnected. •On the other hand, adding one edge to the spanning tree will make it maximally acyclic thereby creating a loop. •A spanning tree does not have a loop or a cycle.
  • 5. SRM Institute of Science and Technology What Is A Minimum Spanning Tree (MST) A minimum spanning tree is the one that contains the least weight among all the other spanning trees of a connected weighted graph. There can be more than one minimum spanning tree for a graph. •Kruskal’s algorithm •Prim’s algorithm
  • 6. SRM Institute of Science and Technology
  • 7. Minimum Spanning Tree - Kruskal’s Algorithm SRM Institute of Science and Technology •Kruskal’s Algorithm is a famous greedy algorithm. •It is used for finding the Minimum Spanning Tree (MST) of a given graph. •To apply Kruskal’s algorithm, the given graph must be weighted, connected and undirected. Kruskal’s Algorithm Implementation- The implementation of Kruskal’s Algorithm is explained in the following steps- Step-01: •Sort all the edges from low weight to high weight. Step-02: •Take the edge with the lowest weight and use it to connect the vertices of graph. •If adding an edge creates a cycle, then reject that edge and go for the next least weight edge.
  • 8. SRM Institute of Science and Technology Step-03: •Keep adding edges until all the vertices are connected and a Minimum Spanning Tree (MST) is obtained. Step 1:Create a forest in such a way that each graph is a separate tree Step 2: Create a priority queue Q that contains all the edges of the graph Step 3: Repeat steps 4 and 5 while Q is NOT EMPTY Step 4: Remove an edge from Q Step 5: If the edge obtained in Step 4 connects two different trees, then Add it to the forest(for combining two trees into one tree). ELSE Discard the edge Step 6: END Kruskal’s Algorithm Note: Forest is a collection of trees
  • 9. SRM Institute of Science and Technology Thumb Rule to Remember The above steps may be reduced to the following thumb rule- •Simply draw all the vertices on the paper. •Connect these vertices using edges with minimum weights such that no cycle gets formed. MST - Kruskal’s Algorithm
  • 10. SRM Institute of Science and Technology PRACTICE PROBLEMS BASED ON KRUSKAL’S ALGORITHM- Problem-01: Construct the minimum spanning tree (MST) for the given graph using Kruskal’s Algorithm- Now we need to find the weight of the minimum spanning tree
  • 11. Solution- To construct MST using Kruskal’s Algorithm, •Simply draw all the vertices on the paper. •Connect these vertices using edges with minimum weights such that no cycle gets formed.- Step-01: Draw all the vertices on the paper as you can see in the Fig No of edges = 9
  • 12. SRM Institute of Science and Technology Write all vertex pair VERTEX PAIR WEIGHT (1,6) 10 (1,2) 28 (2,3) 16 (2,7) 14 (3,4) 12 (4,5) 22 (4,7) 18 (5,6) 25 (5,7) 24
  • 13. SRM Institute of Science and Technology Vertex pair in ascending order VERTEX PAIR WEIGHT (1,6) 10 (3,4) 12 (2,7) 14 (2,3) 16 (4,7) 18 (4,5) 22 (5,7) 24 (5,6) 25 (1,2) 28
  • 14. SRM Institute of Science and Technology Step-02: Step-03: VERTEX PAIR WEIGHT ACTION (1,6) 10 Accepte d (3,4) 12 Accepte d (2,7) 14 (2,3) 16 (4,7) 18 (4,5) 22 (5,7) 24 (5,6) 25 (1,2) 28 Accept the edge if it does not form cycle continue till all nodes are visited Mark 1 if visited the nodes No cycle formation No cycle formation VERTEX KNOWN 1 1 2 0 3 1 4 1 5 0 6 1 7 0
  • 15. SRM Institute of Science and Technology Step-04: Step-05: VERTEX PAIR WEIGHT ACTION (1,6) 10 Accepted (3,4) 12 Accepted (2,7) 14 Accepted (2,3) 16 Accepted (4,7) 18 Rejected (4,5) 22 (5,7) 24 (5,6) 25 (1,2) 28 Accept the edge if it does not form cycle continue till all nodes are visited VERTEX KNOWN 1 1 2 1 3 1 4 1 5 0 6 1 7 1 Mark 1 if visited the nodes No cycle formation
  • 16. SRM Institute of Science and Technology Step-06: Step-07: Accept the edge if it does not form cycle continue till all nodes are visited Since all the vertices have been connected / included in the MST, so we stop. Weight of the MST = Sum of all edge weights = 10 + 25 + 22 + 12 + 16 + 14 VERTEX PAIR WEIGHT ACTION (1,6) 10 Accepted (3,4) 12 Accepted (2,7) 14 Accepted (2,3) 16 Accepted (4,7) 18 Rejected (4,5) 22 Accepted (5,7) 24 Rejected (5,6) 25 Accepted (1,2) 28 VERTEX KNOWN 1 1 2 1 3 1 4 1 5 1 6 1 7 1 Mark 1 if visited the nodes All nodes visited. Stop the Algorithm No cycle formation No cycle formation
  • 17. SRM Institute of Science and Technology Problem 2: Construct the minimum spanning tree (MST) for the given graph using Kruskal’s Algorithm Now we need to find the weight of the minimum spanning tree
  • 18. SRM Institute of Science and Technology V1 V2 V3 V4 V6 V5 Now Let us draw the minimum Spanning Tree using Kruskal’s Algorithm Draw all the vertices on the paper as you can see in the Fig Step 1:
  • 19. SRM Institute of Science and Technology Step 2 Step 3 • We shall connect the vertices using the edges with the least weight • Now, the least weight edge is 3.So the vertices V1 and V2 are connected • Next the least weight edge is 4.So the vertices V1 and V3 are connected. No cycle formation. So accepted. No cycle formation. So accepted.
  • 20. SRM Institute of Science and Technology Step 4 Cycle is not allowed. So rejected. Step 5 • Next least weight edge is 5 which is connecting V3 and V2.But if we include this edge, it will contain a cycle which is not allowed. • Next the least weight edge is 6.So the vertices V2 and V4 are connected. No cycle formation. So accepted.
  • 21. SRM Institute of Science and Technology Step 6 Step 7 Cycle is not allowed. So rejected. • Next least weight edge is 7 which is connecting V3 and V4.But if we include this edge, it will contain a cycle which is not allowed. No cycle formation. So accepted. • Next the least weight edge is 8.So the vertices V3 and V5 are connected.
  • 22. SRM Institute of Science and Technology Step 8 Step 9 • Next least weight edge is 9 which is connecting V4 and V5.But if we include this edge, it will contain a cycle which is not allowed. • Next the least weight edge is 10. So the vertices V4 and V6 are connected. Cycle is not allowed. So rejected. No cycle formation. So accepted.
  • 23. SRM Institute of Science and Technology Step 10 Cycle is not allowed. So rejected. • Next least weight edge is 11 which is connecting V5 and V6.But if we include this edge, it will contain a cycle which is not allowed. Since all the vertices have been connected / included in the MST, so we stop. Weight of the MST = Sum of all edge weights = 3 + 4 + 6 + 8 + 10 = 31 units
  • 24. SRM Institute of Science and Technology NETWORK FLOW PROBLEM – FORD FULKERSON ALGORITHM
  • 25. SRM Institute of Science and Technology
  • 26. SRM Institute of Science and Technology
  • 27. Source S A B C D T Sink flow = 0 0/4 0/9 Flow 0/2 0/8 0/6 Initially flow = 0
  • 28. Source S A B C D T Sink flow = 8 0/4 0/9 Flow 0/2 0/8 0/6 Initially flow = 0 AUGMENTING PATHS BOTTLE NECK CAPCITY S A D T 8 8 8 8 STEP: 1 Minimum capacity
  • 29. Source S A B C D T Sink flow = 8+2=10 0/4 0/9 Flow 0/2 8/8 0/6 Initially flow = 0 AUGMENTING PATHS BOTTLE NECK CAPCITY 2 STEP: 2 Residual capacity = 10 - 8 =2 2 2 8+2 =10 S C D T
  • 30. Source S A B C D T Sink flow = 10+4=14 0/4 2/9 Flow 0/2 8/8 0/6 AUGMENTING PATHS BOTTLE NECK CAPCITY S C D A B T 4 STEP: 3 R capacity = 4 2+4=6 2+4=6 8-4=4 0+4=4 0+4=4 Each and every vertex other than source and sink should have same In-flow and Out-flow
  • 31. Source S A B C D T Sink flow = 14+2=16 4/4 6/9 Flow 0/2 4/8 0/6 AUGMENTING PATHS BOTTLE NECK CAPCITY S A D B T 2 STEP: 4 Same In-flow and Out-flow has to be maintained R capacity = 10-8=2 8+2=10 4+2=6 0+2=2 4+2=6
  • 32. Source S A B C D T Sink flow = 16+3=19 4/4 6/9 Flow 0/2 6/8 2/6 AUGMENTING PATHS BOTTLE NECK CAPCITY S C D B T 3 STEP: 5 R capacity = 9-6=3 6+3=9 6+3=9 2+3=5 6+3=9
  • 33. Source S A B C D T Sink flow = 16+3=19 4/4 9/9 Flow 0/2 6/8 5/6 AUGMENTING PATHS BOTTLE NECK CAPCITY S C D B T 3 STEP: 6 R capacity = 9-6=3
  • 34. SRM Institute of Science and Technology SORTEST PATH ALGORITHM
  • 35. SRM Institute of Science and Technology •Shortest path problem is a problem of finding the shortest path(s) between vertices of a given graph. •Shortest path between two vertices is a path that has the least cost as compared to all other existing paths. Shortest Path Problem- Shortest Path Algorithms- Shortest path algorithms are a family of algorithms used for solving the shortest path problem. Applications- •Google Maps •Road Networks •Logistics Research
  • 36. SRM Institute of Science and Technology Types of Shortest Path Problem- Various types of shortest path problem are- Shortest Path Problems Single Pair Shortest Path Problems Single Source Shortest Path Problems Single destination Shortest Path Problems All Pairs Shortest Path Problems 1.Single-pair shortest path problem 2.Single-source shortest path problem 3.Single-destination shortest path problem 4.All pairs shortest path problem
  • 37. SRM Institute of Science and Technology Single-Pair Shortest Path Problem- •It is a shortest path problem where the shortest path between a given pair of vertices is computed. •A* Search Algorithm is a famous algorithm used for solving single-pair shortest path problem. Single-Source Shortest Path Problem- •It is a shortest path problem where the shortest path from a given source vertex to all other remaining vertices is computed. •Dijkstra’s Algorithm and Bellman Ford Algorithm are the famous algorithms used for solving single-source shortest path problem.
  • 38. SRM Institute of Science and Technology Single-Destination Shortest Path Problem- •It is a shortest path problem where the shortest path from all the vertices to a single destination vertex is computed. •By reversing the direction of each edge in the graph, this problem reduces to single-source shortest path problem. •Dijkstra’s Algorithm is a famous algorithm adapted for solving single-destination shortest path problem. All Pairs Shortest Path Problem- •It is a shortest path problem where the shortest path between every pair of vertices is computed. •Floyd-Warshall Algorithm and Johnson’s Algorithm are the famous algorithms used for solving All pairs shortest path problem.