kruskals prims shared by: geekssay.com
DESCRIPTION
Minimum Spanning trees presentation by: The University of Auckland(Faculty of Education)TRANSCRIPT
![Page 1: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/1.jpg)
Minimum spanning trees
![Page 2: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/2.jpg)
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
![Page 3: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/3.jpg)
A cable company want to connect five villages to their network which currently extends to the market town of Avonford. What is the minimum length of cable needed?
Avonford Fingley
Brinleigh Cornwell
Donster
Edan
2
7
45
8 6 4
5
3
8
Example
![Page 4: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/4.jpg)
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
45
8 6 4
5
3
8
![Page 5: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/5.jpg)
A F
B C
D
E
2
7
45
8 6 4
5
3
8
List the edges in order of size:
ED 2AB 3AE 4CD 4BC 5EF 5CF 6AF 7BF 8CF 8
Kruskal’s Algorithm
![Page 6: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/6.jpg)
Select the shortestedge in the network
ED 2
Kruskal’s Algorithm
A F
B C
D
E
2
7
45
8 6 4
5
3
8
![Page 7: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/7.jpg)
Select the next shortestedge which does notcreate a cycle
ED 2AB 3
Kruskal’s Algorithm
A F
B C
D
E
2
7
45
8 6 4
5
3
8
![Page 8: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/8.jpg)
Select the next shortestedge which does notcreate a cycle
ED 2AB 3CD 4 (or AE 4)
Kruskal’s Algorithm
A F
B C
D
E
2
7
45
8 6 4
5
3
8
![Page 9: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/9.jpg)
Select the next shortestedge which does notcreate a cycle
ED 2AB 3CD 4 AE 4
Kruskal’s Algorithm
A F
B C
D
E
2
7
45
8 6 4
5
3
8
![Page 10: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/10.jpg)
Select the next shortestedge which does notcreate a cycle
ED 2AB 3CD 4 AE 4BC 5 – forms a cycleEF 5
Kruskal’s Algorithm
A F
B C
D
E
2
7
45
8 6 4
5
3
8
![Page 11: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/11.jpg)
All vertices have beenconnected.
The solution is
ED 2AB 3CD 4 AE 4EF 5
Total weight of tree: 18
Kruskal’s Algorithm
A F
B C
D
E
2
7
45
8 6 4
5
3
8
![Page 12: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/12.jpg)
A F
B C
D
E
2
7
45
8 6 4
5
3
8
Select any vertex
A
Select the shortest edge connected to that vertex
AB 3
Prim’s Algorithm
![Page 13: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/13.jpg)
A F
B C
D
E
2
7
45
8 6 4
5
3
8
Select the shortestedge connected to any vertex already connected.
AE 4
Prim’s Algorithm
![Page 14: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/14.jpg)
Select the shortestedge connected to any vertex already connected.
ED 2
Prim’s Algorithm
A F
B C
D
E
2
7
45
8 6 4
5
3
8
![Page 15: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/15.jpg)
Select the shortestedge connected to any vertex already connected.
DC 4
Prim’s Algorithm
A F
B C
D
E
2
7
45
8 6 4
5
3
8
![Page 16: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/16.jpg)
Select the shortestedge connected to any vertex already connected.
CB 5 – forms a cycle
EF 5
Prim’s Algorithm
A F
B C
D
E
2
7
45
8 6 4
5
3
8
![Page 17: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/17.jpg)
Prim’s Algorithm
A F
B C
D
E
2
7
45
8 6 4
5
3
8
All vertices have beenconnected.
The solution is
ED 2AB 3CD 4 AE 4EF 5
Total weight of tree: 18
![Page 18: Kruskals prims shared by: geekssay.com](https://reader033.vdocuments.site/reader033/viewer/2022052906/5589eee1d8b42afa0d8b4762/html5/thumbnails/18.jpg)
•Both algorithms will always give solutions with the same length.
•They will usually select edges in a different order – you must show this in your workings.
•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