SlideShare une entreprise Scribd logo
1  sur  6
Télécharger pour lire hors ligne
© IJCIRAS | ISSN (O) - 2581-5334
January 2018 | Vol. 1 Issue. 8
IJCIRAS1101 WWW.IJCIRAS.COM 35
MINIMUM SPANNING TREE ALGORITHMS AND
TECHNIQUES
Sheikh Irfan Akbar1
, Shahid-ul-Islam 2
1
Computer Science and Technology, RIMT University, Mandi Gobindgarh, Punjab
2
Information Technology, Desh Bhagat University, Mandi Gobindgarh, Punjab
Abstract
A spanning tree is a sub graph obtained from a
connected graph which contains all the vertices of a
graph. For a connected graph there may be many
spanning trees. A minimum spanning tree of a
weighted connected graph is the sub graph with
minimum weight and no cycle. In this research, we
have described the two well-known algorithms
(prim’s algorithm and kruskal’s algorithm) to solve
the minimum spanning tree problem. We have also
described the applications, time complexity and
comparison between the two algorithms. From the
survey we have observed that prim’s algorithm runs
faster than kruskal’s algorithm in dense graphs with
maximum number of edges than vertices.
Keyword: spanning tree, minimum spanning tree,
weighted connected graph, Prim’s algorithm,
Kruskal’s algorithm, complexity.
1.INTRODUCTION
A spanning tree for a connected graph G is defined as
the tree which contain all the vertices of graph G. there
are many spanning trees for a single graph. A spanning
tree is a connected sub graph with no circuits.
Example:
Figure 1 minimum spanning tree example
A minimum spanning tree of a weighted connected
graph G (V, E) is the spanning tree which contains all
the vertices with no cycles and the total weight of the
edges of a tree is minimum. There can be multiple MST
for a single graph but all these MSTs have a unique same
weight.
In this paper we will discuss about the construction of
MST from a weighted graph using different techniques
or algorithms.
2. APPLICATIONS OF MST
I. Network design: The most important application of
MST is in network design including telephone
networks, TV cable network, computer network,
road network, islands connection, pipeline network,
electrical circuits, obtaining an independent set of
circuit equations for an electrical network etc.
II. Approximation algorithm for NP-hard problem:
this application for MST is used to solve travelling
sales man problem.
III. Cluster analysis: k clustering problem can be
viewed as finding an MST and deleting the k-1
edges, i.e. most expensive edges.
IV. Indirect applications: Apart from the above
applications MST have also some indirect
applications.
➢ Max bottleneck paths
➢ LDPC (low density parity check) codes for error
correction
➢ reducing data storage in sequencing amino
acids in a protein – image registration with
Renyi entropy
➢ Model locality of particle interactions in
turbulent fluid flow
➢ learning salient features for real-time face
verification
© IJCIRAS | ISSN (O) - 2581-5334
January 2018 | Vol. 1 Issue. 8
IJCIRAS1101 WWW.IJCIRAS.COM 36
3. MST ALGORITHM
There are various algorithms for minimum spanning
trees. Prim’s, kruskal’s algorithm is the greedy algorithm
which are used to find MST of an undirected weighted
graph, which minimise weight and the number of edges.
3.1. PRIM’S ALGORITHM
The prim’s algorithm was developed in 1930 by Jarnik
and was later rediscovered by Robert C. Prim in 1957
and then again rediscovered by Edsger Dijkstra in 1959.
It is also known as the DJP (Dijkstra-Jarnik Problem)
algorithm, or the Jarnik algorithm, or the Prim–Jarnik
algorithm.
The prim’s algorithm is the greedy algorithm used to
find the minimum cost spanning tree for an undirected
weighted graph.
3.1.1. STEPS IN PRIM’S ALGORITHM
1. Initialise the tree with a single vertex from a given
graph.
2. Choose the shortest outgoing edge from the node
and add this to the tree.
3. The edge formed by the two vertices is treated as a
single node, we check for the shortest adjacent edge
to the node and add this to the tree.
4. Repeat the steps until all the vertices are added to
the tree.
3.1.2. Pseudo code
Algorithm: PRIM (G)
Input: A weighted graph G
Output: A minimum spanning tree T for graph G.
1. Make a queue (Q) for all vertices of the graph G.
2. Set the priority to infinity to all the vertices except
for the starting vertex whose priority is set to 0.
3. Pick any vertex v from G.
4. v
5. D[u] 0
6. E[u] ← ∅
7. while Q ≠ ∅
8. u ← Q.removeMinElement()
9. add vertex u and edge (u,E[u]) to T
10. for each vertex z adjacent to u do
11. if z is in Q
12. if weight(u, z) < D[z] then
13. D[z] ← weight(u, z)
14. E[z] ← (u, z)
15. change the key of z in Q to D[z]
16. return tree T
Example:
G= {V, E}
V= {A, B, C, D, E, F}
Step1: choose a source vertex A from the above graph.
Q = {B, C, D, E, F)
Step2: vertex A is the source vertex v.
Adjacent vertices= {B, D, E}
Choose edge {A, E}
Q = {B, D, E, F)
© IJCIRAS | ISSN (O) - 2581-5334
January 2018 | Vol. 1 Issue. 8
IJCIRAS1101 WWW.IJCIRAS.COM 37
Step3:
Adjacent vertices= {B, D, C}
Shortest edge {E, C}
Q = {B, D, F)
Step4:
Adjacent vertices= {B, D, F}
Shortest edge {A, B}
Q = {D, F)
Step5:
Adjacent vertices= {D, F}
Shortest edge {C, D}
Q = {F}
Step6:
Adjacent vertices= {F}
Shortest edge {D, F}
Q = {∅}
Now we have the minimum spanning tree obtained
from the graph G, which includes the edges {A, E}, {E, C},
{A, B}, {C, D}, {D, F}.
3.2. KRUSKAL’s ALGORITHM
Kruskal’s algorithm is named after Joseph Kruskal.it was
developed in 1956. Kruskal’s Algorithm is based on the
greedy algorithm. The greedy method is applied as we
pick the smallest weight edge that does not cause a
cycle in the MST constructed so far. Kruskal’s algorithm
forms the forest where each edge acts vertex acts as a
single tree, the edges are sorted in the increasing order
of their costs and included in the set T of selected edges
if the edges in the selected tree do not form a cycle and
also after the inclusion of edges. Kruskal’s algorithm also
works on the disconnected graphs.
3.2.1. STEPS IN KRUSKAL’S ALGORITHM
1. Sort all the edges in the increasing order of their
cost.
2. Choose the edge which has the smallest cost and
check for the cycle. If the edge forms the cycle with
© IJCIRAS | ISSN (O) - 2581-5334
January 2018 | Vol. 1 Issue. 8
IJCIRAS1101 WWW.IJCIRAS.COM 38
the spanning tree discard that edge else include the
edge in the spanning tree.
3. Repeat step 2 until all the vertices are included in
the spanning tree.
3.2.2. Pseudo code
MST-Kruskal (G, W)
Input: undirected graph G = (V, E)
W = E R
Output: minimum spanning tree T
1. T = ∅;
T (the final spanning tree) is defined to be the
empty set;
2. For each vertex v of G do
3. Make empty set out of v.
4. Sort the edges of graph ‘G’ in the increasing
order of their weight w.
5. For each edge (u, v) from the sorted edges do
6. If u and v belong to different sets then
7. Add (u,v) to T;
8. Union (u, v);
9. Return T;
EXAMPLE:
We have a graph G (V, E) shown in the fig below:
Set of edges Weight (
increasing order )
Edge included
E C 1 yes
A E 3 yes
A B 5 yes
D F 7 yes
C D 9 yes
B E 10 yes
A D 12 No
B C 16 No
C F 17 No
Step1: Include edge {E, C} which has lowest weight.
Step2: edge {A, E} is the next highest edge added to the
tree.
© IJCIRAS | ISSN (O) - 2581-5334
January 2018 | Vol. 1 Issue. 8
IJCIRAS1101 WWW.IJCIRAS.COM 39
Step3: Edge {A, B} is added to the tree.
Step4: Edge {D, F} is added to the tree, which forms the
disconnected tree.
Step5: Next edge {D, C} is added to the tree, the edge
joins the two trees.
All the vertices are included in the tree. This is the final
minimum spanning tree which has the minimum weight
among all the spanning trees. The edges {E, C}, {A, E}, {A,
B}, {D, F}, {C, D}.
4. COMPARISON BETWEEN PRIM’S AND KRUSKAL’S
ALGORITHM
1. Prim’s algorithm begins with a node while as
kruskal’s algorithm starts with an edge.
2. Prim’s algorithm works only on connected graphs,
while as kruskal’s algorithm can also be applied on
disconnected graphs.
3. Prim’s algorithm builds the minimum spanning tree
by adding a vertex, while as kruskal’s algorithm
works on adding an edge at a time.
4. The time complexity of prim’s algorithm (O(V2)) is
less than that of kruskal’s algorithm (O(logV)).
5. HISTORY AND FURTHER READINGS
Ronald Graham and Pavol Hell in the research paper
describes the history of the problem up to 1985. The first
known MST algorithm was proposed by Otakar Bor˚uvka
in1926. He was a great Czech mathematician. He was
considering an efficient electrical coverage of Bohemia
at that time. In the mid-1950s when the computer age
just began, the MST problem was further solved by
many researchers. Among them, Joseph Kruskal and
Robert Prim gave two commonly used algorithms. Both
of them writes about Bor˚uvka’s paper in their books.
Prim’s algorithm was a rediscovery of the algorithm by
the prominent number theoretician Vojtˇech Jarn´ık.
These algorithms run in O(m log n) time.
Andrew Chi-Chih Yao, David Cheriton and Robert Tarjan
© IJCIRAS | ISSN (O) - 2581-5334
January 2018 | Vol. 1 Issue. 8
IJCIRAS1101 WWW.IJCIRAS.COM 40
made improvements which reduces the time complexity
to O(m log log n). With the invention of Fibonacci heaps,
the complexity was further reduced. In the worst case, m
= O(n) and the running time is O(m log∗ m). The
complexity was further minimised to O(m log β(m, n)) by
Harold N. Gabow, Thomas H. Spencer, and Robert
Tarjan. David Karger, Philip Klein, and Robert Tarjan
proposed a randomized linear-time algorithm for
finding a minimum spanning tree in the restricted
random-access model. Robert Tarjan gave a linear-time
algorithm by using path compression. J´anos Koml´os
showed that we can verify the minimum spanning tree
in linear number of comparisons. Dixon, Monika Rauch,
and Robert Tarjan gave the first linear-time verification
algorithm .linear time algorithm for finding the
minimum spanning tree remains an open problem.
6. CONCLUSION
In this paper we have discussed about well-known
algorithms to construct and find the minimum spanning
tree of an undirected and connected graph: Prim’s
algorithm, and Kruskal’s algorithm. It is observed that
the time complexity of prim’s algorithm is less than
kruskal’s algorithm. The prim’s algorithm is simple to
implement. Prim’s algorithm and kruskal’s algorithms
are mostly used for solving MST problem among the
other algorithms. We are further looking to reduce the
time complexity of MST algorithms.
REFERENCES
[1] Abhilasha.R, “Minimum Cost Spanning Tree Using
Prim’s Algorithm,” International Journal of Advance
Research in computer science and management studies,
vol. 1, june 2013.
[2] D. K. M. Patel, Nimesh Patel, “A Survey on:
Enhancement of Minimum Spanning Tree,” Nimesh
Patel International Journal of Engineering Research and
Applications, vol. 5, january 2015.
[3] Jayanta Dutta. S.C.Pal, Ardhendu Mandal, “A New
Efficient Technique to Construct a Minimum Spanning
Tree,” International Journal of Advanced Research in
Computer Science and Software Engineering, oct, 2012.
[4] Neetu Rawat, “AN Algorithmic Approach To Graph
Theory,” in International Conference on Advances in
Engineering & Technology,, Goa,INDIA, 2014.
[5] R.Kalaivani, Dr.D vijayalakshmir, “Minimum Cost
Spanning Tree using Matrix Algorithm,” International
Journal of Scientific and Research Publications, vol. 4,
september 2014.

Contenu connexe

Similaire à MST Algorithms: Prim's and Kruskal's Algorithm Comparison

OTP, Phishing, QR code, Shares, Visual Cryptography.
OTP, Phishing, QR code, Shares, Visual Cryptography.OTP, Phishing, QR code, Shares, Visual Cryptography.
OTP, Phishing, QR code, Shares, Visual Cryptography.IJERA Editor
 
Shortest path by using suitable algorithm.pdf
Shortest path by using suitable algorithm.pdfShortest path by using suitable algorithm.pdf
Shortest path by using suitable algorithm.pdfzefergaming
 
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...KUSHDHIRRA2111026030
 
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra Sahil Kumar
 
04 15029 active node ijeecs 1570310145(edit)
04 15029 active node ijeecs 1570310145(edit)04 15029 active node ijeecs 1570310145(edit)
04 15029 active node ijeecs 1570310145(edit)nooriasukmaningtyas
 
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEA NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEijscmcj
 
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEA NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEijscmc
 
Prim's and Kruskal's Algorithm
Prim's and Kruskal's AlgorithmPrim's and Kruskal's Algorithm
Prim's and Kruskal's AlgorithmOmTanna1
 
Ram minimum spanning tree
Ram   minimum spanning treeRam   minimum spanning tree
Ram minimum spanning treeRama Prasath A
 
Final_Report_Rohit-Neha
Final_Report_Rohit-NehaFinal_Report_Rohit-Neha
Final_Report_Rohit-Nehaneha agarwal
 
Decision Maths 1 Chapter 3 Algorithms on Graphs (including Floyd A2 content)....
Decision Maths 1 Chapter 3 Algorithms on Graphs (including Floyd A2 content)....Decision Maths 1 Chapter 3 Algorithms on Graphs (including Floyd A2 content)....
Decision Maths 1 Chapter 3 Algorithms on Graphs (including Floyd A2 content)....SintooChauhan6
 
On Projected Newton Barrier Methods for Linear Programming and an Equivalence...
On Projected Newton Barrier Methods for Linear Programming and an Equivalence...On Projected Newton Barrier Methods for Linear Programming and an Equivalence...
On Projected Newton Barrier Methods for Linear Programming and an Equivalence...SSA KPI
 
Traveling Salesman Problem in Distributed Environment
Traveling Salesman Problem in Distributed EnvironmentTraveling Salesman Problem in Distributed Environment
Traveling Salesman Problem in Distributed Environmentcsandit
 
TRAVELING SALESMAN PROBLEM IN DISTRIBUTED ENVIRONMENT
TRAVELING SALESMAN PROBLEM IN DISTRIBUTED ENVIRONMENTTRAVELING SALESMAN PROBLEM IN DISTRIBUTED ENVIRONMENT
TRAVELING SALESMAN PROBLEM IN DISTRIBUTED ENVIRONMENTcscpconf
 
Minimum spanning tree (mst)
Minimum spanning tree (mst)Minimum spanning tree (mst)
Minimum spanning tree (mst)Pradeep Behera
 

Similaire à MST Algorithms: Prim's and Kruskal's Algorithm Comparison (20)

OTP, Phishing, QR code, Shares, Visual Cryptography.
OTP, Phishing, QR code, Shares, Visual Cryptography.OTP, Phishing, QR code, Shares, Visual Cryptography.
OTP, Phishing, QR code, Shares, Visual Cryptography.
 
Shortest path by using suitable algorithm.pdf
Shortest path by using suitable algorithm.pdfShortest path by using suitable algorithm.pdf
Shortest path by using suitable algorithm.pdf
 
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
 
1 sollins algorithm
1 sollins algorithm1 sollins algorithm
1 sollins algorithm
 
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
 
04 15029 active node ijeecs 1570310145(edit)
04 15029 active node ijeecs 1570310145(edit)04 15029 active node ijeecs 1570310145(edit)
04 15029 active node ijeecs 1570310145(edit)
 
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEA NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
 
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEA NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
 
8_MST_pptx.pptx
8_MST_pptx.pptx8_MST_pptx.pptx
8_MST_pptx.pptx
 
Prim's and Kruskal's Algorithm
Prim's and Kruskal's AlgorithmPrim's and Kruskal's Algorithm
Prim's and Kruskal's Algorithm
 
Daa chapter13
Daa chapter13Daa chapter13
Daa chapter13
 
Ram minimum spanning tree
Ram   minimum spanning treeRam   minimum spanning tree
Ram minimum spanning tree
 
Final_Report_Rohit-Neha
Final_Report_Rohit-NehaFinal_Report_Rohit-Neha
Final_Report_Rohit-Neha
 
Decision Maths 1 Chapter 3 Algorithms on Graphs (including Floyd A2 content)....
Decision Maths 1 Chapter 3 Algorithms on Graphs (including Floyd A2 content)....Decision Maths 1 Chapter 3 Algorithms on Graphs (including Floyd A2 content)....
Decision Maths 1 Chapter 3 Algorithms on Graphs (including Floyd A2 content)....
 
On Projected Newton Barrier Methods for Linear Programming and an Equivalence...
On Projected Newton Barrier Methods for Linear Programming and an Equivalence...On Projected Newton Barrier Methods for Linear Programming and an Equivalence...
On Projected Newton Barrier Methods for Linear Programming and an Equivalence...
 
APPLICATION OF NUMERICAL METHODS IN SMALL SIZE
APPLICATION OF NUMERICAL METHODS IN SMALL SIZEAPPLICATION OF NUMERICAL METHODS IN SMALL SIZE
APPLICATION OF NUMERICAL METHODS IN SMALL SIZE
 
Traveling Salesman Problem in Distributed Environment
Traveling Salesman Problem in Distributed EnvironmentTraveling Salesman Problem in Distributed Environment
Traveling Salesman Problem in Distributed Environment
 
TRAVELING SALESMAN PROBLEM IN DISTRIBUTED ENVIRONMENT
TRAVELING SALESMAN PROBLEM IN DISTRIBUTED ENVIRONMENTTRAVELING SALESMAN PROBLEM IN DISTRIBUTED ENVIRONMENT
TRAVELING SALESMAN PROBLEM IN DISTRIBUTED ENVIRONMENT
 
Minimum spanning tree (mst)
Minimum spanning tree (mst)Minimum spanning tree (mst)
Minimum spanning tree (mst)
 
Network analysis
Network analysisNetwork analysis
Network analysis
 

Dernier

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Dernier (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

MST Algorithms: Prim's and Kruskal's Algorithm Comparison

  • 1. © IJCIRAS | ISSN (O) - 2581-5334 January 2018 | Vol. 1 Issue. 8 IJCIRAS1101 WWW.IJCIRAS.COM 35 MINIMUM SPANNING TREE ALGORITHMS AND TECHNIQUES Sheikh Irfan Akbar1 , Shahid-ul-Islam 2 1 Computer Science and Technology, RIMT University, Mandi Gobindgarh, Punjab 2 Information Technology, Desh Bhagat University, Mandi Gobindgarh, Punjab Abstract A spanning tree is a sub graph obtained from a connected graph which contains all the vertices of a graph. For a connected graph there may be many spanning trees. A minimum spanning tree of a weighted connected graph is the sub graph with minimum weight and no cycle. In this research, we have described the two well-known algorithms (prim’s algorithm and kruskal’s algorithm) to solve the minimum spanning tree problem. We have also described the applications, time complexity and comparison between the two algorithms. From the survey we have observed that prim’s algorithm runs faster than kruskal’s algorithm in dense graphs with maximum number of edges than vertices. Keyword: spanning tree, minimum spanning tree, weighted connected graph, Prim’s algorithm, Kruskal’s algorithm, complexity. 1.INTRODUCTION A spanning tree for a connected graph G is defined as the tree which contain all the vertices of graph G. there are many spanning trees for a single graph. A spanning tree is a connected sub graph with no circuits. Example: Figure 1 minimum spanning tree example A minimum spanning tree of a weighted connected graph G (V, E) is the spanning tree which contains all the vertices with no cycles and the total weight of the edges of a tree is minimum. There can be multiple MST for a single graph but all these MSTs have a unique same weight. In this paper we will discuss about the construction of MST from a weighted graph using different techniques or algorithms. 2. APPLICATIONS OF MST I. Network design: The most important application of MST is in network design including telephone networks, TV cable network, computer network, road network, islands connection, pipeline network, electrical circuits, obtaining an independent set of circuit equations for an electrical network etc. II. Approximation algorithm for NP-hard problem: this application for MST is used to solve travelling sales man problem. III. Cluster analysis: k clustering problem can be viewed as finding an MST and deleting the k-1 edges, i.e. most expensive edges. IV. Indirect applications: Apart from the above applications MST have also some indirect applications. ➢ Max bottleneck paths ➢ LDPC (low density parity check) codes for error correction ➢ reducing data storage in sequencing amino acids in a protein – image registration with Renyi entropy ➢ Model locality of particle interactions in turbulent fluid flow ➢ learning salient features for real-time face verification
  • 2. © IJCIRAS | ISSN (O) - 2581-5334 January 2018 | Vol. 1 Issue. 8 IJCIRAS1101 WWW.IJCIRAS.COM 36 3. MST ALGORITHM There are various algorithms for minimum spanning trees. Prim’s, kruskal’s algorithm is the greedy algorithm which are used to find MST of an undirected weighted graph, which minimise weight and the number of edges. 3.1. PRIM’S ALGORITHM The prim’s algorithm was developed in 1930 by Jarnik and was later rediscovered by Robert C. Prim in 1957 and then again rediscovered by Edsger Dijkstra in 1959. It is also known as the DJP (Dijkstra-Jarnik Problem) algorithm, or the Jarnik algorithm, or the Prim–Jarnik algorithm. The prim’s algorithm is the greedy algorithm used to find the minimum cost spanning tree for an undirected weighted graph. 3.1.1. STEPS IN PRIM’S ALGORITHM 1. Initialise the tree with a single vertex from a given graph. 2. Choose the shortest outgoing edge from the node and add this to the tree. 3. The edge formed by the two vertices is treated as a single node, we check for the shortest adjacent edge to the node and add this to the tree. 4. Repeat the steps until all the vertices are added to the tree. 3.1.2. Pseudo code Algorithm: PRIM (G) Input: A weighted graph G Output: A minimum spanning tree T for graph G. 1. Make a queue (Q) for all vertices of the graph G. 2. Set the priority to infinity to all the vertices except for the starting vertex whose priority is set to 0. 3. Pick any vertex v from G. 4. v 5. D[u] 0 6. E[u] ← ∅ 7. while Q ≠ ∅ 8. u ← Q.removeMinElement() 9. add vertex u and edge (u,E[u]) to T 10. for each vertex z adjacent to u do 11. if z is in Q 12. if weight(u, z) < D[z] then 13. D[z] ← weight(u, z) 14. E[z] ← (u, z) 15. change the key of z in Q to D[z] 16. return tree T Example: G= {V, E} V= {A, B, C, D, E, F} Step1: choose a source vertex A from the above graph. Q = {B, C, D, E, F) Step2: vertex A is the source vertex v. Adjacent vertices= {B, D, E} Choose edge {A, E} Q = {B, D, E, F)
  • 3. © IJCIRAS | ISSN (O) - 2581-5334 January 2018 | Vol. 1 Issue. 8 IJCIRAS1101 WWW.IJCIRAS.COM 37 Step3: Adjacent vertices= {B, D, C} Shortest edge {E, C} Q = {B, D, F) Step4: Adjacent vertices= {B, D, F} Shortest edge {A, B} Q = {D, F) Step5: Adjacent vertices= {D, F} Shortest edge {C, D} Q = {F} Step6: Adjacent vertices= {F} Shortest edge {D, F} Q = {∅} Now we have the minimum spanning tree obtained from the graph G, which includes the edges {A, E}, {E, C}, {A, B}, {C, D}, {D, F}. 3.2. KRUSKAL’s ALGORITHM Kruskal’s algorithm is named after Joseph Kruskal.it was developed in 1956. Kruskal’s Algorithm is based on the greedy algorithm. The greedy method is applied as we pick the smallest weight edge that does not cause a cycle in the MST constructed so far. Kruskal’s algorithm forms the forest where each edge acts vertex acts as a single tree, the edges are sorted in the increasing order of their costs and included in the set T of selected edges if the edges in the selected tree do not form a cycle and also after the inclusion of edges. Kruskal’s algorithm also works on the disconnected graphs. 3.2.1. STEPS IN KRUSKAL’S ALGORITHM 1. Sort all the edges in the increasing order of their cost. 2. Choose the edge which has the smallest cost and check for the cycle. If the edge forms the cycle with
  • 4. © IJCIRAS | ISSN (O) - 2581-5334 January 2018 | Vol. 1 Issue. 8 IJCIRAS1101 WWW.IJCIRAS.COM 38 the spanning tree discard that edge else include the edge in the spanning tree. 3. Repeat step 2 until all the vertices are included in the spanning tree. 3.2.2. Pseudo code MST-Kruskal (G, W) Input: undirected graph G = (V, E) W = E R Output: minimum spanning tree T 1. T = ∅; T (the final spanning tree) is defined to be the empty set; 2. For each vertex v of G do 3. Make empty set out of v. 4. Sort the edges of graph ‘G’ in the increasing order of their weight w. 5. For each edge (u, v) from the sorted edges do 6. If u and v belong to different sets then 7. Add (u,v) to T; 8. Union (u, v); 9. Return T; EXAMPLE: We have a graph G (V, E) shown in the fig below: Set of edges Weight ( increasing order ) Edge included E C 1 yes A E 3 yes A B 5 yes D F 7 yes C D 9 yes B E 10 yes A D 12 No B C 16 No C F 17 No Step1: Include edge {E, C} which has lowest weight. Step2: edge {A, E} is the next highest edge added to the tree.
  • 5. © IJCIRAS | ISSN (O) - 2581-5334 January 2018 | Vol. 1 Issue. 8 IJCIRAS1101 WWW.IJCIRAS.COM 39 Step3: Edge {A, B} is added to the tree. Step4: Edge {D, F} is added to the tree, which forms the disconnected tree. Step5: Next edge {D, C} is added to the tree, the edge joins the two trees. All the vertices are included in the tree. This is the final minimum spanning tree which has the minimum weight among all the spanning trees. The edges {E, C}, {A, E}, {A, B}, {D, F}, {C, D}. 4. COMPARISON BETWEEN PRIM’S AND KRUSKAL’S ALGORITHM 1. Prim’s algorithm begins with a node while as kruskal’s algorithm starts with an edge. 2. Prim’s algorithm works only on connected graphs, while as kruskal’s algorithm can also be applied on disconnected graphs. 3. Prim’s algorithm builds the minimum spanning tree by adding a vertex, while as kruskal’s algorithm works on adding an edge at a time. 4. The time complexity of prim’s algorithm (O(V2)) is less than that of kruskal’s algorithm (O(logV)). 5. HISTORY AND FURTHER READINGS Ronald Graham and Pavol Hell in the research paper describes the history of the problem up to 1985. The first known MST algorithm was proposed by Otakar Bor˚uvka in1926. He was a great Czech mathematician. He was considering an efficient electrical coverage of Bohemia at that time. In the mid-1950s when the computer age just began, the MST problem was further solved by many researchers. Among them, Joseph Kruskal and Robert Prim gave two commonly used algorithms. Both of them writes about Bor˚uvka’s paper in their books. Prim’s algorithm was a rediscovery of the algorithm by the prominent number theoretician Vojtˇech Jarn´ık. These algorithms run in O(m log n) time. Andrew Chi-Chih Yao, David Cheriton and Robert Tarjan
  • 6. © IJCIRAS | ISSN (O) - 2581-5334 January 2018 | Vol. 1 Issue. 8 IJCIRAS1101 WWW.IJCIRAS.COM 40 made improvements which reduces the time complexity to O(m log log n). With the invention of Fibonacci heaps, the complexity was further reduced. In the worst case, m = O(n) and the running time is O(m log∗ m). The complexity was further minimised to O(m log β(m, n)) by Harold N. Gabow, Thomas H. Spencer, and Robert Tarjan. David Karger, Philip Klein, and Robert Tarjan proposed a randomized linear-time algorithm for finding a minimum spanning tree in the restricted random-access model. Robert Tarjan gave a linear-time algorithm by using path compression. J´anos Koml´os showed that we can verify the minimum spanning tree in linear number of comparisons. Dixon, Monika Rauch, and Robert Tarjan gave the first linear-time verification algorithm .linear time algorithm for finding the minimum spanning tree remains an open problem. 6. CONCLUSION In this paper we have discussed about well-known algorithms to construct and find the minimum spanning tree of an undirected and connected graph: Prim’s algorithm, and Kruskal’s algorithm. It is observed that the time complexity of prim’s algorithm is less than kruskal’s algorithm. The prim’s algorithm is simple to implement. Prim’s algorithm and kruskal’s algorithms are mostly used for solving MST problem among the other algorithms. We are further looking to reduce the time complexity of MST algorithms. REFERENCES [1] Abhilasha.R, “Minimum Cost Spanning Tree Using Prim’s Algorithm,” International Journal of Advance Research in computer science and management studies, vol. 1, june 2013. [2] D. K. M. Patel, Nimesh Patel, “A Survey on: Enhancement of Minimum Spanning Tree,” Nimesh Patel International Journal of Engineering Research and Applications, vol. 5, january 2015. [3] Jayanta Dutta. S.C.Pal, Ardhendu Mandal, “A New Efficient Technique to Construct a Minimum Spanning Tree,” International Journal of Advanced Research in Computer Science and Software Engineering, oct, 2012. [4] Neetu Rawat, “AN Algorithmic Approach To Graph Theory,” in International Conference on Advances in Engineering & Technology,, Goa,INDIA, 2014. [5] R.Kalaivani, Dr.D vijayalakshmir, “Minimum Cost Spanning Tree using Matrix Algorithm,” International Journal of Scientific and Research Publications, vol. 4, september 2014.