SlideShare a Scribd company logo
1 of 16
Data Structure and Algorithm
Minimum Cost Spanning Tree
Submitted by,
M. Kavitha,
II – M.Sc(CS&IT),
Nadar Saraswathi College of
Arts & Science, Theni.
Data Structure and Algorithm
Contents :
1. Minimum Cost Spanning Tree
1.1. Prim’s Algorithm
1.2. Kruskal’s Algorithm
1.3. An Optimal Randomized Algorithm (*)
Minimum – Cost Spanning Tree
Definition :
* Let G = (V,E) be an undirected connected graph.
* A sub-graph t = (V,E’) of G is a spanning tree of
G iff t is a tree.
1
2
376
5 4
10
28
14 16
24
25
22
18 12
1
2
376
5
4
10
14 16
25
22
12
Fig 1 : Graph and minimum – cost spanning tree
Prim’s Algorithm
* A greedy method to obtain a minimum-cost spanning
tree builds the tree edge by edge.
* Prim's algorithm finds a minimum spanning tree
(MST) for a connected weighted graph.
* MST = subset of edges that forms a tree including
every vertex, such that total weight of all edges is minimum cost
spanning.
There are two possible ways:
1. The set of edges so far selected form a tree. If A is the set
of edges selected so far then A forms a tree.
2. The next edge (u,v) to be include in A is a minimum-cost
edge not in A with the property that AU{(u,v)} is also a tree.
1
2
376
5
4
1
2
376
5
4
10
25
10
(A) (B)
1
2
376
5
4
10
25
22
(C)
Stages in Prim’s Algorithm :
1
2
376
5
4
10
25
22
12
1
2
376
5
4
10
16
25
22
12
1
2
376
5
4
10
14 16
25
22
12
(D) (E)
(F)
* The algorithm is a minimum cost spanning tree
includes for each vertex v a minimum-cost edge incident to v.
* It support t is a minimum-cost spanning tree for G =
(V,E).
* These algorithms find the minimum spanning forest
in a possibly disconnected graph.
* The most basic form of Prim's algorithm only finds
minimum spanning trees in connected graphs.
mincost :=0;
for i:=2 to n do near[i]:=1;
// Vertex 1 is initially in t.
near[i]:=0;
for i:=1 to n-1 do
{
// Find n-1 edges for t.
Algorithm Prim(E,cost,n,t)
{
Let(k,l) be an edge of minimum cost in E;
mincost:=cost[k,l];
t[1,1]:=k; t[1,2]:=l;
for i:=1 to n do
if (cost[i,l]<cost[i,k])then near[i]:=l;
Else near[i]:=k;
near[k]:=near[l]:=0;
for i:=2 to n-1 do {
Let j be an index such that near[j]≠0 and
cost[j,near[j]] is minimum;
t[i,1]:=j;t[i,2]:=near[j];
mincost:=mincost+cost[j,near[j]];
near[j]:=0;
for k:=1 to n do
if((near[k]≠0)and(cost[k,near[k]]>cost[k,j]))
then near[k]:=j; }
return mincost;
}
Prim’s minimum-cost
spanning tree algorithm
kruskal’s Algorithm
* Kruskal's algorithm is a greedy algorithm in graph
theory that finds a minimum spanning tree for a connected
weighted graph.
* This means it finds a subset of the edges that forms
a tree that includes every vertex, where the total weight of all
the edges in the tree is minimized.
* If the graph is not connected, then it finds a
minimum spanning forest (a minimum spanning tree for each
connected component).
* Kruskal's Algorithm add edges in increasing weight,
skipping those whose addition would create a cycle.
1
2
376
5
4
1
2
376
5
4
10
1
2
376
5
4
10
12
(A)
(c)
(B)
Stages in Kruskal’s Algorithm :
1
2
37
6
5
4
1
2
376
5
4
10
1
2
376
5
4
10
12
(D)
(F)
(E)
10
12
14
14 16
12
14 16
22
t:=0;
while (t has less than n-1 edges) and (E≠0)) do
{
Choose an edge(v,w) from E of lowest cost;
Delete (v,w) from E;
if (v,w) does not create a cycle in t then add (v,w) to t;
else discard (v,w);
}
1.Would create a cycle if v and w are already in the
same component.
2. I We start with a component for each node.
3. I Components merge when we add an edge.
4. Need a way to: check if v and w are in same
component and to merge two components into one.
Algorithm Kruskal(E,cost,n,t)
{
Construct a heap out of the edge costs using
Heapify;
for i:=1 to n do parent[i]:=-1;
i:=0; mincost:=0.0;
While((i<n-1) and (heap not empty)) do {
Delete a minimum cost edge (u,v) from the
heap and reheapify using Adjust;
j:=Find(u);k:=Find(v);
if(j≠k) then {
i:=i+1;
t[i,1]:=u;t[i,2]:=v;
mincost:=mincost+cost[u,v];
Union(j,k);
} }
if(i≠n-1) then write(“No spanning tree”);
else return mincost;
}
Kruskal’s Algorithm
An Optimal Randomized Algorithm (*)
* The minimum-cost spanning tree of a graph G(V,E) to
spend Ω(|V|+|E|) time in worst case.
* A randomized algorithm that runs in time the
Õ(|V|+|E|) can be devised :
1. Randomly sample m edges from G (for some suitable m).
2. Let G’ be the induced sub graph that is G’ has V as its
node set and the sampled edges in its edge set.
3. The sub graph G’ need not be connected a minimum-cost
spanning tree for each component of G;.
4. Let F be the minimum-cost spanning tree forest of G’.
5. F eliminate edges called the F-heavy edges of G that
cannot possibly be in a minimum-cost spanning tree.
Thank You

More Related Content

What's hot

Shortest path problem
Shortest path problemShortest path problem
Shortest path problemIfra Ilyas
 
Prim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treeoneous
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithmmeisamstar
 
Dijkstra’S Algorithm
Dijkstra’S AlgorithmDijkstra’S Algorithm
Dijkstra’S Algorithmami_01
 
Numerical on dichotomous search
Numerical on dichotomous searchNumerical on dichotomous search
Numerical on dichotomous searchSumita Das
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's AlgorithmArijitDhali
 
Algorithms explained
Algorithms explainedAlgorithms explained
Algorithms explainedPIYUSH Dubey
 
Discrete Mathematics Presentation
Discrete Mathematics PresentationDiscrete Mathematics Presentation
Discrete Mathematics PresentationSalman Elahi
 
Numerical on bisection method
Numerical on bisection methodNumerical on bisection method
Numerical on bisection methodSumita Das
 
Numerical Methods in Mechanical Engineering - Final Project
Numerical Methods in Mechanical Engineering - Final ProjectNumerical Methods in Mechanical Engineering - Final Project
Numerical Methods in Mechanical Engineering - Final ProjectStasik Nemirovsky
 
Networks dijkstra's algorithm- pgsr
Networks  dijkstra's algorithm- pgsrNetworks  dijkstra's algorithm- pgsr
Networks dijkstra's algorithm- pgsrLinawati Adiman
 
Graph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answersGraph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answersAnimesh Chaturvedi
 

What's hot (18)

Shortest path problem
Shortest path problemShortest path problem
Shortest path problem
 
Prim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning tree
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithm
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Dijkstra’S Algorithm
Dijkstra’S AlgorithmDijkstra’S Algorithm
Dijkstra’S Algorithm
 
Numerical on dichotomous search
Numerical on dichotomous searchNumerical on dichotomous search
Numerical on dichotomous search
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
 
Luis ppt
Luis pptLuis ppt
Luis ppt
 
Algorithms explained
Algorithms explainedAlgorithms explained
Algorithms explained
 
Discrete Mathematics Presentation
Discrete Mathematics PresentationDiscrete Mathematics Presentation
Discrete Mathematics Presentation
 
Numerical on bisection method
Numerical on bisection methodNumerical on bisection method
Numerical on bisection method
 
8.5 Bingo
8.5 Bingo8.5 Bingo
8.5 Bingo
 
8.5 Bingo
8.5 Bingo8.5 Bingo
8.5 Bingo
 
Numerical Methods in Mechanical Engineering - Final Project
Numerical Methods in Mechanical Engineering - Final ProjectNumerical Methods in Mechanical Engineering - Final Project
Numerical Methods in Mechanical Engineering - Final Project
 
Shortest path algorithm
Shortest  path algorithmShortest  path algorithm
Shortest path algorithm
 
Networks dijkstra's algorithm- pgsr
Networks  dijkstra's algorithm- pgsrNetworks  dijkstra's algorithm- pgsr
Networks dijkstra's algorithm- pgsr
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
 
Graph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answersGraph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answers
 

Similar to Data structure

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
 
Ireducible core and equal remaining obligations rule for mcst games
Ireducible core and equal remaining obligations rule for mcst gamesIreducible core and equal remaining obligations rule for mcst games
Ireducible core and equal remaining obligations rule for mcst gamesvinnief
 
Proportional and decentralized rule mcst games
Proportional and decentralized rule mcst gamesProportional and decentralized rule mcst games
Proportional and decentralized rule mcst gamesvinnief
 
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest pathArafat Hossan
 
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
 
Unit 3 - Greedy Method
Unit 3  - Greedy MethodUnit 3  - Greedy Method
Unit 3 - Greedy MethodMaryJacob24
 
Unit 3 greedy method
Unit 3  greedy methodUnit 3  greedy method
Unit 3 greedy methodMaryJacob24
 
Giáo trình Phân tích và thiết kế giải thuật - CHAP 8
Giáo trình Phân tích và thiết kế giải thuật - CHAP 8Giáo trình Phân tích và thiết kế giải thuật - CHAP 8
Giáo trình Phân tích và thiết kế giải thuật - CHAP 8Nguyễn Công Hoàng
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9chidabdu
 
sublabel accurate convex relaxation of vectorial multilabel energies
sublabel accurate convex relaxation of vectorial multilabel energiessublabel accurate convex relaxation of vectorial multilabel energies
sublabel accurate convex relaxation of vectorial multilabel energiesFujimoto Keisuke
 
Ijciras1101
Ijciras1101Ijciras1101
Ijciras1101zhendy94
 

Similar to Data structure (20)

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
 
Weighted graphs
Weighted graphsWeighted graphs
Weighted graphs
 
Ireducible core and equal remaining obligations rule for mcst games
Ireducible core and equal remaining obligations rule for mcst gamesIreducible core and equal remaining obligations rule for mcst games
Ireducible core and equal remaining obligations rule for mcst games
 
Lecture26
Lecture26Lecture26
Lecture26
 
Proportional and decentralized rule mcst games
Proportional and decentralized rule mcst gamesProportional and decentralized rule mcst games
Proportional and decentralized rule mcst games
 
Daa chapter11
Daa chapter11Daa chapter11
Daa chapter11
 
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest path
 
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
 
Unit 3 - Greedy Method
Unit 3  - Greedy MethodUnit 3  - Greedy Method
Unit 3 - Greedy Method
 
Unit 3 greedy method
Unit 3  greedy methodUnit 3  greedy method
Unit 3 greedy method
 
Giáo trình Phân tích và thiết kế giải thuật - CHAP 8
Giáo trình Phân tích và thiết kế giải thuật - CHAP 8Giáo trình Phân tích và thiết kế giải thuật - CHAP 8
Giáo trình Phân tích và thiết kế giải thuật - CHAP 8
 
Chap07alg
Chap07algChap07alg
Chap07alg
 
Chap07alg
Chap07algChap07alg
Chap07alg
 
MST
MSTMST
MST
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9
 
Dijkstra
DijkstraDijkstra
Dijkstra
 
sublabel accurate convex relaxation of vectorial multilabel energies
sublabel accurate convex relaxation of vectorial multilabel energiessublabel accurate convex relaxation of vectorial multilabel energies
sublabel accurate convex relaxation of vectorial multilabel energies
 
Chapter 24 aoa
Chapter 24 aoaChapter 24 aoa
Chapter 24 aoa
 
Ijciras1101
Ijciras1101Ijciras1101
Ijciras1101
 

More from kavitha muneeshwaran (13)

Physical Security
Physical SecurityPhysical Security
Physical Security
 
Digital Audio
Digital AudioDigital Audio
Digital Audio
 
Java
JavaJava
Java
 
Internet Programming with Java
Internet Programming with JavaInternet Programming with Java
Internet Programming with Java
 
Digital image processing
Digital image processing  Digital image processing
Digital image processing
 
Staffing level estimation
Staffing level estimation Staffing level estimation
Staffing level estimation
 
Data Integration and Transformation in Data mining
Data Integration and Transformation in Data miningData Integration and Transformation in Data mining
Data Integration and Transformation in Data mining
 
Transaction Management - Deadlock Handling
Transaction Management - Deadlock HandlingTransaction Management - Deadlock Handling
Transaction Management - Deadlock Handling
 
Process
ProcessProcess
Process
 
Digital Logic circuit
Digital Logic circuitDigital Logic circuit
Digital Logic circuit
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
I/O system in intel 80386 microcomputer architecture
I/O system in intel 80386 microcomputer architectureI/O system in intel 80386 microcomputer architecture
I/O system in intel 80386 microcomputer architecture
 
narrow Band ISDN
narrow Band ISDNnarrow Band ISDN
narrow Band ISDN
 

Recently uploaded

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
 
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
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
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
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
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
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 

Recently uploaded (20)

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
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
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...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.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
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
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
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 

Data structure

  • 1. Data Structure and Algorithm Minimum Cost Spanning Tree Submitted by, M. Kavitha, II – M.Sc(CS&IT), Nadar Saraswathi College of Arts & Science, Theni.
  • 2. Data Structure and Algorithm Contents : 1. Minimum Cost Spanning Tree 1.1. Prim’s Algorithm 1.2. Kruskal’s Algorithm 1.3. An Optimal Randomized Algorithm (*)
  • 3. Minimum – Cost Spanning Tree Definition : * Let G = (V,E) be an undirected connected graph. * A sub-graph t = (V,E’) of G is a spanning tree of G iff t is a tree. 1 2 376 5 4 10 28 14 16 24 25 22 18 12 1 2 376 5 4 10 14 16 25 22 12 Fig 1 : Graph and minimum – cost spanning tree
  • 4. Prim’s Algorithm * A greedy method to obtain a minimum-cost spanning tree builds the tree edge by edge. * Prim's algorithm finds a minimum spanning tree (MST) for a connected weighted graph. * MST = subset of edges that forms a tree including every vertex, such that total weight of all edges is minimum cost spanning. There are two possible ways: 1. The set of edges so far selected form a tree. If A is the set of edges selected so far then A forms a tree. 2. The next edge (u,v) to be include in A is a minimum-cost edge not in A with the property that AU{(u,v)} is also a tree.
  • 7. * The algorithm is a minimum cost spanning tree includes for each vertex v a minimum-cost edge incident to v. * It support t is a minimum-cost spanning tree for G = (V,E). * These algorithms find the minimum spanning forest in a possibly disconnected graph. * The most basic form of Prim's algorithm only finds minimum spanning trees in connected graphs. mincost :=0; for i:=2 to n do near[i]:=1; // Vertex 1 is initially in t. near[i]:=0; for i:=1 to n-1 do { // Find n-1 edges for t.
  • 8. Algorithm Prim(E,cost,n,t) { Let(k,l) be an edge of minimum cost in E; mincost:=cost[k,l]; t[1,1]:=k; t[1,2]:=l; for i:=1 to n do if (cost[i,l]<cost[i,k])then near[i]:=l; Else near[i]:=k; near[k]:=near[l]:=0; for i:=2 to n-1 do { Let j be an index such that near[j]≠0 and cost[j,near[j]] is minimum; t[i,1]:=j;t[i,2]:=near[j]; mincost:=mincost+cost[j,near[j]]; near[j]:=0; for k:=1 to n do if((near[k]≠0)and(cost[k,near[k]]>cost[k,j])) then near[k]:=j; } return mincost; } Prim’s minimum-cost spanning tree algorithm
  • 9. kruskal’s Algorithm * Kruskal's algorithm is a greedy algorithm in graph theory that finds a minimum spanning tree for a connected weighted graph. * This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. * If the graph is not connected, then it finds a minimum spanning forest (a minimum spanning tree for each connected component). * Kruskal's Algorithm add edges in increasing weight, skipping those whose addition would create a cycle.
  • 12. t:=0; while (t has less than n-1 edges) and (E≠0)) do { Choose an edge(v,w) from E of lowest cost; Delete (v,w) from E; if (v,w) does not create a cycle in t then add (v,w) to t; else discard (v,w); } 1.Would create a cycle if v and w are already in the same component. 2. I We start with a component for each node. 3. I Components merge when we add an edge. 4. Need a way to: check if v and w are in same component and to merge two components into one.
  • 13. Algorithm Kruskal(E,cost,n,t) { Construct a heap out of the edge costs using Heapify; for i:=1 to n do parent[i]:=-1; i:=0; mincost:=0.0; While((i<n-1) and (heap not empty)) do { Delete a minimum cost edge (u,v) from the heap and reheapify using Adjust; j:=Find(u);k:=Find(v); if(j≠k) then { i:=i+1; t[i,1]:=u;t[i,2]:=v; mincost:=mincost+cost[u,v]; Union(j,k); } } if(i≠n-1) then write(“No spanning tree”); else return mincost; } Kruskal’s Algorithm
  • 14. An Optimal Randomized Algorithm (*) * The minimum-cost spanning tree of a graph G(V,E) to spend Ω(|V|+|E|) time in worst case. * A randomized algorithm that runs in time the Õ(|V|+|E|) can be devised : 1. Randomly sample m edges from G (for some suitable m). 2. Let G’ be the induced sub graph that is G’ has V as its node set and the sampled edges in its edge set. 3. The sub graph G’ need not be connected a minimum-cost spanning tree for each component of G;. 4. Let F be the minimum-cost spanning tree forest of G’. 5. F eliminate edges called the F-heavy edges of G that cannot possibly be in a minimum-cost spanning tree.
  • 15.