![Page 1: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/1.jpg)
Spanning Trees
![Page 2: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/2.jpg)
Prim’s MST Algorithm
Algorithm ( this is also greedy)
Select an arbitrary vertex to start the tree,
while there are fringe vertices:
1)select an edge of minimum weight
between a tree vertex and a fringe
vertex.
2)add the selected edge and the
fringe vertex to the tree.
end.
![Page 3: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/3.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
3
2
1
4
4
2
5
3
4
7 8
1
6
2
52
6
![Page 4: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/4.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
3
2
1
4
4
2
5
3
4
7 8
1
6
2
52
6
Example: start with 7Example: start with 7
![Page 5: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/5.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
3
2
1
4
4
2
5
3
4
7 8
1
6
2
52
6
![Page 6: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/6.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
3
2
1
4
4
2
5
3
4
7 8
1
6
2
52
6
![Page 7: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/7.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
3
2
1
4
4
2
5
3
4
7 8
1
6
2
52
6
![Page 8: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/8.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
3
2
1
4
4
2
5
3
4
7 8
1
2
52
6
![Page 9: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/9.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
3
2
1
4
4
2
5
3
4
7 8
1
2
52
6
![Page 10: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/10.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
3
2
1
4
4
2
5
3
4
7 8
1
2
56
![Page 11: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/11.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
3
2
1
4
4
2
5
3
4
7 8
1
2
56
![Page 12: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/12.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
2
1
4
4
2
5
3
4
7 8
1
2
6
![Page 13: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/13.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
2
1
4
4
2
5
3
4
7 8
1
2
6
![Page 14: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/14.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
2
1 4
2
5
3
4
7 8
1
2
6
![Page 15: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/15.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
2
1 4
2
5
3
4
7 8
1
2
6
![Page 16: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/16.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
2
1
2
5
3
4
7 8
1
2
![Page 17: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/17.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
2
1
2
5
3
4
7 8
1
2
![Page 18: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/18.jpg)
Prim’s AlgorithmMinimal Spanning Tree
1 6
2 4
3 5
2
1
2
3
7 8
1
2
MST weight = 15MST weight = 15
4
![Page 19: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/19.jpg)
Topological Sorting Algorithm
while (the graph has a node with no successor) do
remove one of those nodes from the graph
and add it to the end of a list
if (the graph is empty) then
the list contains the reverse of some topological order
else
the graph contains a cycle
![Page 20: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/20.jpg)
AA
BB
CC
DD
EE
FF
GG
HH II
JJ
LL
KK
MM
![Page 21: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/21.jpg)
AA
BB
CC
DD
EE
FF
GG
HH II
JJ
LL
KK
MM
DD
![Page 22: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/22.jpg)
AA
BB
CC
EE
FF
GG
HH II
JJ
LL
KK
MM
DD EE
![Page 23: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/23.jpg)
AA
BB
CC
FF
GG
HH II
JJ
LL
KK
MM
DD EE FF
![Page 24: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/24.jpg)
AA
BB
CCGG
HH II
JJ
LL
KK
MM
DD EE FF CC
![Page 25: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/25.jpg)
AA
BB
GG
HH II
JJ
LL
KK
MM
DD EE FF CC BB
![Page 26: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/26.jpg)
AA
GG
HH II
JJ
LL
KK
MM
DD EE FF CC BB II
![Page 27: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/27.jpg)
AA
GG
HH
JJ
LL
KK
MM
DD EE FF CC BB II HH
![Page 28: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/28.jpg)
AA
GG
JJ
LL
KK
MM
DD EE FF CC BB II HH GG
![Page 29: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/29.jpg)
AA
JJ
LL
KK
MM
DD EE FF CC BB II HH GG AA
![Page 30: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/30.jpg)
JJ
LL
KK
MM
DD EE FF CC BB II HH GG AA KK
![Page 31: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/31.jpg)
JJ
LL MM
DD EE FF CC BB II HH GG AA KK MM
![Page 32: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/32.jpg)
JJ
LL
DD EE FF CC BB II HH GG AA KK MM LL
![Page 33: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/33.jpg)
JJ
DD EE FF CC BB II HH GG AA KK MM LL JJ
![Page 34: Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select](https://reader035.vdocument.in/reader035/viewer/2022062618/5513f9e2550346e2488b458a/html5/thumbnails/34.jpg)
DD EE FF CC BB II HH GG AA KK MM LL JJ
J L M K A G H I B C F E DJ L M K A G H I B C F E D