SlideShare une entreprise Scribd logo
1  sur  23
Minimum spanning treesMinimum spanning trees
1
MST
A minimum spanning tree connects all nodes in a given graph
A MST must be a connected and undirected graph
A MST can have weighted edges
Multiple MSTs can exist within a given undirected graph
Multiple MSTs can be generated depending on which algorithm is
used
If you wish to have an MST start at a specific node
However, if there are weighted edges and all weighted edges are
unique, only one MST will exist
2
Borůvka’s Algorithm
• The first MST Algorithm was created by
Otakar Borůvka in 1926
• The algorithm was used to create efficient
connections between the electricity
network in the Czech Republic
• No longer used since Prim’s and Kruskal’s
algorithms were discovered
3
Prim’s Algorithm
• Initially discovered in 1930 by Vojtěch
Jarník, then rediscovered in 1957 by
Robert C. Prim
• Similar to Dijkstra’s Algorithm regarding a
connected graph
• Starts off by picking any node within the
graph and growing from there
4
Kruskal’s Algorithm
• Created in 1957 by Joseph Kruskal
• Finds the MST by taking the smallest weight in the graph
and connecting the two nodes and repeating until all
nodes are connected to just one tree
• This is done by creating a priority queue using the
weights as keys
• Each node starts off as it’s own tree
• While the queue is not empty, if the edge retrieved
connects two trees, connect them, if not, discard it
• Once the queue is empty, you are left with the minimum
spanning tree
5
Minimum Connector Algorithms
Kruskal’s algorithm
1. Select the shortest edge in a
network
2. Select the next shortest edge
which does not create a cycle
3. Repeat step 2 until all vertices
have been connected
Prim’s algorithm
1. Select any vertex
2. Select the shortest edge
connected to that vertex
3. Select the shortest edge
connected to any vertex
already connected
4. Repeat step 3 until all
vertices have been
connected
Prim’s algorithm
1. Select any vertex
2. Select the shortest edge
connected to that vertex
3. Select the shortest edge
connected to any vertex
already connected
4. Repeat step 3 until all
vertices have been
connected
6
A cable company want to connect five villages to their network
which currently extends to the market town of Addis Ababa. What
is the minimum length of cable needed?
Addis Hawassa
Adama Awash
Dilla
Wolita
2
7
4
5
8 6
4
5
3
8
Example
7
We model the situation as a network, then the
problem is to find the minimum connector for the
network
A F
B C
D
E
2
7
4
5
8 6
4
5
3
8
8
A
F
B
C
D
E
2
7
4
5
8 6
4
5
3
8
List the edges in
order of size:
ED 2
AB 3
AE 4
CD 4
BC 5
EF 5
CF 6
AF 7
BF 8
CF 8
Kruskal’s Algorithm
9
Select the shortest
edge in the network
ED 2
Kruskal’s Algorithm
A
F
B
C
D
E
2
7
4
5
8 6
4
5
3
8
10
Select the next shortest
edge which does not
create a cycle
ED 2
AB 3
Kruskal’s Algorithm
A
F
B
C
D
E
2
7
4
5
8 6
4
5
3
8
11
Select the next shortest
edge which does not
create a cycle
ED 2
AB 3
CD 4 (or AE 4)
Kruskal’s Algorithm
A
F
B
C
D
E
2
7
4
5
8 6
4
5
3
8
12
Select the next shortest
edge which does not
create a cycle
ED 2
AB 3
CD 4
AE 4
Kruskal’s Algorithm
A
F
B
C
D
E
2
7
4
5
8 6
4
5
3
8
13
Select the next shortest
edge which does not
create a cycle
ED 2
AB 3
CD 4
AE 4
BC 5 – forms a cycle
EF 5
Kruskal’s Algorithm
A
F
B
C
D
E
2
7
4
5
8 6
4
5
3
8
14
All vertices have been
connected.
The solution is
ED 2
AB 3
CD 4
AE 4
EF 5
Total weight of tree: 18
Kruskal’s Algorithm
A
F
B
C
D
E
2
7
4
5
8 6
4
5
3
8
15
A
F
B
C
D
E
2
7
4
5
8 6
4
5
3
8
Select any vertex
A
Select the shortest
edge connected to
that vertex
AB 3
Prim’s Algorithm
16
A
F
B
C
D
E
2
7
4
5
8 6
4
5
3
8
Select the shortest
edge connected to
any vertex already
connected.
AE 4
Prim’s Algorithm
17
Select the shortest
edge connected to
any vertex already
connected.
ED 2
Prim’s Algorithm
A
F
B
C
D
E
2
7
4
5
8 6
4
5
3
8
18
Select the shortest
edge connected to
any vertex already
connected.
DC 4
Prim’s Algorithm
A
F
B
C
D
E
2
7
4
5
8 6
4
5
3
8
19
Select the shortest
edge connected to
any vertex already
connected.
EF 5
Prim’s Algorithm
A
F
B
C
D
E
2
7
4
5
8 6
4
5
3
8
20
Prim’s Algorithm
A
F
B
C
D
E
2
7
4
5
8 6
4
5
3
8
All vertices have been
connected.
The solution is
AB 3
AE 4
ED 2
DC 4
EF 5
Total weight of tree: 18
21
•Both algorithms will always give solutions with the
same length.
•They will usually select edges in a different order
•Occasionally they will use different edges – this
may happen when you have to choose between
edges with the same length. In this case there is
more than one minimum connector for the
network.
Some points to note
22
Questions?
23

Contenu connexe

Tendances

Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data StructureAnuj Modi
 
minimum spanning trees Algorithm
minimum spanning trees Algorithm minimum spanning trees Algorithm
minimum spanning trees Algorithm sachin varun
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structurehamza javed
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithmsSaga Valsalan
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentationSubid Biswas
 
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
 
Single source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraSingle source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraRoshan Tailor
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree Divya Ks
 
Prims & kruskal algorithms
Prims & kruskal algorithmsPrims & kruskal algorithms
Prims & kruskal algorithmsAyesha Tahir
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structurehafsa komal
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithmfaisal2204
 
Kruskal & Prim's Algorithm
Kruskal & Prim's AlgorithmKruskal & Prim's Algorithm
Kruskal & Prim's AlgorithmIfad Rahman
 

Tendances (20)

Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 
minimum spanning trees Algorithm
minimum spanning trees Algorithm minimum spanning trees Algorithm
minimum spanning trees Algorithm
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
 
Shortest Path in Graph
Shortest Path in GraphShortest Path in Graph
Shortest Path in Graph
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 
PRIM'S ALGORITHM
PRIM'S ALGORITHMPRIM'S ALGORITHM
PRIM'S ALGORITHM
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
 
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
 
Single source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraSingle source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstra
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 
Prims & kruskal algorithms
Prims & kruskal algorithmsPrims & kruskal algorithms
Prims & kruskal algorithms
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structure
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithm
 
Kruskal & Prim's Algorithm
Kruskal & Prim's AlgorithmKruskal & Prim's Algorithm
Kruskal & Prim's Algorithm
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
 

En vedette

Happy workers happy library
Happy workers happy libraryHappy workers happy library
Happy workers happy libraryllwyatt
 
Upplýsingtækni í árborg 18.5.2015
Upplýsingtækni í árborg 18.5.2015Upplýsingtækni í árborg 18.5.2015
Upplýsingtækni í árborg 18.5.2015Margret2008
 
Acc 557 homework 1 5 complete solution
Acc 557 homework 1 5 complete solutionAcc 557 homework 1 5 complete solution
Acc 557 homework 1 5 complete solutionRenea Barrera
 
Iowa assessments practice problems
Iowa assessments practice problemsIowa assessments practice problems
Iowa assessments practice problemsbweldon
 
Comp1900 Tahseen
Comp1900 TahseenComp1900 Tahseen
Comp1900 Tahseentahseen ali
 
http://whatisarsi.carpaltunnelnaturalcures.com
http://whatisarsi.carpaltunnelnaturalcures.comhttp://whatisarsi.carpaltunnelnaturalcures.com
http://whatisarsi.carpaltunnelnaturalcures.comJames Blackstone
 
Trabajo informaticaopenofficegeorgigenadiev
Trabajo informaticaopenofficegeorgigenadievTrabajo informaticaopenofficegeorgigenadiev
Trabajo informaticaopenofficegeorgigenadievGeorgiGenadiev
 
Academic english1124
Academic english1124Academic english1124
Academic english1124Miri Komatsu
 
Foto premiazione (id)art_fest2011
Foto premiazione (id)art_fest2011Foto premiazione (id)art_fest2011
Foto premiazione (id)art_fest2011Alfonso Caputo
 
The world has changed retail - 24 august 2010
The world has changed   retail - 24 august 2010The world has changed   retail - 24 august 2010
The world has changed retail - 24 august 2010Mark Sinclair
 
Cary Nadler, Phd.
Cary Nadler, Phd.Cary Nadler, Phd.
Cary Nadler, Phd.rearden638
 

En vedette (17)

India
IndiaIndia
India
 
olproject
olprojectolproject
olproject
 
Happy workers happy library
Happy workers happy libraryHappy workers happy library
Happy workers happy library
 
Upplýsingtækni í árborg 18.5.2015
Upplýsingtækni í árborg 18.5.2015Upplýsingtækni í árborg 18.5.2015
Upplýsingtækni í árborg 18.5.2015
 
Acc 557 homework 1 5 complete solution
Acc 557 homework 1 5 complete solutionAcc 557 homework 1 5 complete solution
Acc 557 homework 1 5 complete solution
 
Iowa assessments practice problems
Iowa assessments practice problemsIowa assessments practice problems
Iowa assessments practice problems
 
Comp1900 Tahseen
Comp1900 TahseenComp1900 Tahseen
Comp1900 Tahseen
 
http://whatisarsi.carpaltunnelnaturalcures.com
http://whatisarsi.carpaltunnelnaturalcures.comhttp://whatisarsi.carpaltunnelnaturalcures.com
http://whatisarsi.carpaltunnelnaturalcures.com
 
Cassandra At Wize Commerce
Cassandra At Wize CommerceCassandra At Wize Commerce
Cassandra At Wize Commerce
 
Trabajo informaticaopenofficegeorgigenadiev
Trabajo informaticaopenofficegeorgigenadievTrabajo informaticaopenofficegeorgigenadiev
Trabajo informaticaopenofficegeorgigenadiev
 
Phys LO
Phys LOPhys LO
Phys LO
 
Academic english1124
Academic english1124Academic english1124
Academic english1124
 
Kaspersky
KasperskyKaspersky
Kaspersky
 
Foto premiazione (id)art_fest2011
Foto premiazione (id)art_fest2011Foto premiazione (id)art_fest2011
Foto premiazione (id)art_fest2011
 
The world has changed retail - 24 august 2010
The world has changed   retail - 24 august 2010The world has changed   retail - 24 august 2010
The world has changed retail - 24 august 2010
 
Cary Nadler, Phd.
Cary Nadler, Phd.Cary Nadler, Phd.
Cary Nadler, Phd.
 
Anegats
AnegatsAnegats
Anegats
 

Similaire à minimum spanning tree

APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...KUSHDHIRRA2111026030
 
kruskal.ppt
kruskal.pptkruskal.ppt
kruskal.ppterosslo
 
Ram minimum spanning tree
Ram   minimum spanning treeRam   minimum spanning tree
Ram minimum spanning treeRama Prasath A
 
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
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning TreeBalamurugan M
 
DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM
DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHMDATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM
DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHMABIRAMIS87
 
MinSpanningTreespresantion.ppt
MinSpanningTreespresantion.pptMinSpanningTreespresantion.ppt
MinSpanningTreespresantion.pptbaciprek
 
Prim's and Kruskal's Algorithm
Prim's and Kruskal's AlgorithmPrim's and Kruskal's Algorithm
Prim's and Kruskal's AlgorithmOmTanna1
 
Ijciras1101
Ijciras1101Ijciras1101
Ijciras1101zhendy94
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sJay Patel
 
15 chapter9 graph_algorithms_mst
15 chapter9 graph_algorithms_mst15 chapter9 graph_algorithms_mst
15 chapter9 graph_algorithms_mstSSE_AndyLi
 
prim's and kruskal's algorithm
prim's and kruskal's algorithmprim's and kruskal's algorithm
prim's and kruskal's algorithmshreeuva
 
Minimum Spanning Tree Optimizations
Minimum Spanning Tree OptimizationsMinimum Spanning Tree Optimizations
Minimum Spanning Tree OptimizationsRandy Cornell
 

Similaire à minimum spanning tree (20)

APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
 
kruskal.ppt
kruskal.pptkruskal.ppt
kruskal.ppt
 
kruskal prim
kruskal primkruskal prim
kruskal prim
 
Ram minimum spanning tree
Ram   minimum spanning treeRam   minimum spanning tree
Ram minimum spanning tree
 
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)....
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Tree
 
DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM
DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHMDATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM
DATA STRUCTURE AND ALGORITHM LMS MST KRUSKAL'S ALGORITHM
 
Lec33
Lec33Lec33
Lec33
 
Network flow
Network flowNetwork flow
Network flow
 
MinSpanningTreespresantion.ppt
MinSpanningTreespresantion.pptMinSpanningTreespresantion.ppt
MinSpanningTreespresantion.ppt
 
Prim's and Kruskal's Algorithm
Prim's and Kruskal's AlgorithmPrim's and Kruskal's Algorithm
Prim's and Kruskal's Algorithm
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
OR II - M3.pptx
OR II - M3.pptxOR II - M3.pptx
OR II - M3.pptx
 
1 sollins algorithm
1 sollins algorithm1 sollins algorithm
1 sollins algorithm
 
Unit3_1.pdf
Unit3_1.pdfUnit3_1.pdf
Unit3_1.pdf
 
Ijciras1101
Ijciras1101Ijciras1101
Ijciras1101
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
 
15 chapter9 graph_algorithms_mst
15 chapter9 graph_algorithms_mst15 chapter9 graph_algorithms_mst
15 chapter9 graph_algorithms_mst
 
prim's and kruskal's algorithm
prim's and kruskal's algorithmprim's and kruskal's algorithm
prim's and kruskal's algorithm
 
Minimum Spanning Tree Optimizations
Minimum Spanning Tree OptimizationsMinimum Spanning Tree Optimizations
Minimum Spanning Tree Optimizations
 

Plus de Melaku Bayih Demessie (10)

Chapter 4 computer network and the internet2
Chapter 4 computer network and the internet2Chapter 4 computer network and the internet2
Chapter 4 computer network and the internet2
 
Introduction to Cloud computing
Introduction to Cloud computingIntroduction to Cloud computing
Introduction to Cloud computing
 
Selected topics in Computer Science
Selected topics in Computer Science Selected topics in Computer Science
Selected topics in Computer Science
 
Turingmachines
Turingmachines Turingmachines
Turingmachines
 
Greencomputing
GreencomputingGreencomputing
Greencomputing
 
Reed solomon code
Reed solomon codeReed solomon code
Reed solomon code
 
C2.0 propositional logic
C2.0 propositional logicC2.0 propositional logic
C2.0 propositional logic
 
Chapter 5 of 1
Chapter 5 of 1Chapter 5 of 1
Chapter 5 of 1
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 

minimum spanning tree

  • 1. Minimum spanning treesMinimum spanning trees 1
  • 2. MST A minimum spanning tree connects all nodes in a given graph A MST must be a connected and undirected graph A MST can have weighted edges Multiple MSTs can exist within a given undirected graph Multiple MSTs can be generated depending on which algorithm is used If you wish to have an MST start at a specific node However, if there are weighted edges and all weighted edges are unique, only one MST will exist 2
  • 3. Borůvka’s Algorithm • The first MST Algorithm was created by Otakar Borůvka in 1926 • The algorithm was used to create efficient connections between the electricity network in the Czech Republic • No longer used since Prim’s and Kruskal’s algorithms were discovered 3
  • 4. Prim’s Algorithm • Initially discovered in 1930 by Vojtěch Jarník, then rediscovered in 1957 by Robert C. Prim • Similar to Dijkstra’s Algorithm regarding a connected graph • Starts off by picking any node within the graph and growing from there 4
  • 5. Kruskal’s Algorithm • Created in 1957 by Joseph Kruskal • Finds the MST by taking the smallest weight in the graph and connecting the two nodes and repeating until all nodes are connected to just one tree • This is done by creating a priority queue using the weights as keys • Each node starts off as it’s own tree • While the queue is not empty, if the edge retrieved connects two trees, connect them, if not, discard it • Once the queue is empty, you are left with the minimum spanning tree 5
  • 6. Minimum Connector Algorithms Kruskal’s algorithm 1. Select the shortest edge in a network 2. Select the next shortest edge which does not create a cycle 3. Repeat step 2 until all vertices have been connected Prim’s algorithm 1. Select any vertex 2. Select the shortest edge connected to that vertex 3. Select the shortest edge connected to any vertex already connected 4. Repeat step 3 until all vertices have been connected Prim’s algorithm 1. Select any vertex 2. Select the shortest edge connected to that vertex 3. Select the shortest edge connected to any vertex already connected 4. Repeat step 3 until all vertices have been connected 6
  • 7. A cable company want to connect five villages to their network which currently extends to the market town of Addis Ababa. What is the minimum length of cable needed? Addis Hawassa Adama Awash Dilla Wolita 2 7 4 5 8 6 4 5 3 8 Example 7
  • 8. We model the situation as a network, then the problem is to find the minimum connector for the network A F B C D E 2 7 4 5 8 6 4 5 3 8 8
  • 9. A F B C D E 2 7 4 5 8 6 4 5 3 8 List the edges in order of size: ED 2 AB 3 AE 4 CD 4 BC 5 EF 5 CF 6 AF 7 BF 8 CF 8 Kruskal’s Algorithm 9
  • 10. Select the shortest edge in the network ED 2 Kruskal’s Algorithm A F B C D E 2 7 4 5 8 6 4 5 3 8 10
  • 11. Select the next shortest edge which does not create a cycle ED 2 AB 3 Kruskal’s Algorithm A F B C D E 2 7 4 5 8 6 4 5 3 8 11
  • 12. Select the next shortest edge which does not create a cycle ED 2 AB 3 CD 4 (or AE 4) Kruskal’s Algorithm A F B C D E 2 7 4 5 8 6 4 5 3 8 12
  • 13. Select the next shortest edge which does not create a cycle ED 2 AB 3 CD 4 AE 4 Kruskal’s Algorithm A F B C D E 2 7 4 5 8 6 4 5 3 8 13
  • 14. Select the next shortest edge which does not create a cycle ED 2 AB 3 CD 4 AE 4 BC 5 – forms a cycle EF 5 Kruskal’s Algorithm A F B C D E 2 7 4 5 8 6 4 5 3 8 14
  • 15. All vertices have been connected. The solution is ED 2 AB 3 CD 4 AE 4 EF 5 Total weight of tree: 18 Kruskal’s Algorithm A F B C D E 2 7 4 5 8 6 4 5 3 8 15
  • 16. A F B C D E 2 7 4 5 8 6 4 5 3 8 Select any vertex A Select the shortest edge connected to that vertex AB 3 Prim’s Algorithm 16
  • 17. A F B C D E 2 7 4 5 8 6 4 5 3 8 Select the shortest edge connected to any vertex already connected. AE 4 Prim’s Algorithm 17
  • 18. Select the shortest edge connected to any vertex already connected. ED 2 Prim’s Algorithm A F B C D E 2 7 4 5 8 6 4 5 3 8 18
  • 19. Select the shortest edge connected to any vertex already connected. DC 4 Prim’s Algorithm A F B C D E 2 7 4 5 8 6 4 5 3 8 19
  • 20. Select the shortest edge connected to any vertex already connected. EF 5 Prim’s Algorithm A F B C D E 2 7 4 5 8 6 4 5 3 8 20
  • 21. Prim’s Algorithm A F B C D E 2 7 4 5 8 6 4 5 3 8 All vertices have been connected. The solution is AB 3 AE 4 ED 2 DC 4 EF 5 Total weight of tree: 18 21
  • 22. •Both algorithms will always give solutions with the same length. •They will usually select edges in a different order •Occasionally they will use different edges – this may happen when you have to choose between edges with the same length. In this case there is more than one minimum connector for the network. Some points to note 22