Presentation is loading. Please wait.

Presentation is loading. Please wait.

Minimum spanning trees

Similar presentations


Presentation on theme: "Minimum spanning trees"— Presentation transcript:

1 Minimum spanning trees

2 Minimum Connector Algorithms
Kruskal’s algorithm Select the shortest edge in a network Select the next shortest edge which does not create a cycle Repeat step 2 until all vertices have been connected Prim’s algorithm Select any vertex Select the shortest edge connected to that vertex Select the shortest edge connected to any vertex already connected Repeat step 3 until all vertices have been connected

3 Minimum Connector Algorithms
NO CYCLES!

4 Example 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 4 5 8 6 3

5 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 3

6 Kruskal’s Algorithm B C 3 6 8 A D F 7 5 4 2 E
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 A F B C D E 2 7 4 5 8 6 3

7 Kruskal’s Algorithm Select the shortest edge in the network B C 3 6 8
F B C D E 2 7 4 5 8 6 3

8 Kruskal’s Algorithm B C 3 6 8 A D F 7 5 4 2 E Select the next shortest
edge which does not create a cycle ED 2 AB 3 A F B C D E 2 7 4 5 8 6 3

9 Kruskal’s Algorithm B C 3 6 8 A D F 7 5 4 2 E Select the next shortest
edge which does not create a cycle ED 2 AB 3 CD 4 (or AE 4) A F B C D E 2 7 4 5 8 6 3

10 Kruskal’s Algorithm B C 3 6 8 A D F 7 5 4 2 E Select the next shortest
edge which does not create a cycle ED 2 AB 3 CD 4 AE 4 A F B C D E 2 7 4 5 8 6 3

11 Kruskal’s Algorithm B C 3 6 8 A D F 7 5 4 2 E 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 A F B C D E 2 7 4 5 8 6 3

12 Kruskal’s Algorithm B C 3 6 8 A D F 7 5 4 2 E All vertices have been
connected. The solution is ED 2 AB 3 CD 4 AE 4 EF 5 Total weight of tree: 18 A F B C D E 2 7 4 5 8 6 3

13 Prim’s Algorithm B C 3 6 8 A D F 7 5 4 2 E Select any vertex A
Select the shortest edge connected to that vertex AB 3 A F B C D E 2 7 4 5 8 6 3

14 Prim’s Algorithm B C 3 6 8 A D F 7 5 4 2 E Select the shortest
edge connected to any vertex already connected. AE 4 A F B C D E 2 7 4 5 8 6 3

15 Prim’s Algorithm B C 3 6 8 A D F 7 5 4 2 E Select the shortest
edge connected to any vertex already connected. ED 2 A F B C D E 2 7 4 5 8 6 3

16 Prim’s Algorithm B C 3 6 8 A D F 7 5 4 2 E Select the shortest
edge connected to any vertex already connected. DC 4 A F B C D E 2 7 4 5 8 6 3

17 Prim’s Algorithm B C 3 6 8 A D F 7 5 4 2 E Select the shortest
edge connected to any vertex already connected. EF 5 A F B C D E 2 7 4 5 8 6 3

18 Prim’s Algorithm B C 3 6 8 A D F 7 5 4 2 E All vertices have been
connected. The solution is AB 3 AE 4 ED 2 DC 4 EF 5 Total weight of tree: 18 A F B C D E 2 7 4 5 8 6 3

19 Prim’s Algorithm B C 3 A D F 5 4 2 E All vertices have been connected.
The solution is AB 3 AE 4 ED 2 DC 4 EF 5 Total weight of tree: 18 A F B C D E 2 4 5 3

20 Some points to note 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.

21

22 F 3 B

23 F 3 B 4 C

24 F 3 B 4 C

25 6 F E 3 B 4 C

26 6 F E 3 6 B G D 4 C

27 6 F E 3 7 6 B G D 4 C

28 6 7 F E A 3 7 6 B G D 4 C

29 6 7 F E A 3 7 6 B G D 4 C Total Weight of Tree: 33


Download ppt "Minimum spanning trees"

Similar presentations


Ads by Google