Minimum spanning trees Minimum Connector Algorithms Kruskals algorithm

  • Slides: 11
Download presentation
Minimum spanning trees

Minimum spanning trees

Minimum Connector Algorithms Kruskal’s algorithm 1. 2. 3. Select the shortest edge in a

Minimum Connector Algorithms Kruskal’s algorithm 1. 2. 3. Select the shortest edge in a network 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 Select the next shortest edge which does not create a cycle Repeat step 2 until all vertices have been connected

Example A cable company want to connect five villages to their network which currently

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? 5 Brinleigh Cornwell 3 4 6 8 8 Avonford 7 4 Fingley 5 2 Edan Donster

We model the situation as a network, then the problem is to find the

We model the situation as a network, then the problem is to find the minimum connector for the network 5 B C 3 4 6 8 8 A F 7 5 4 2 E D

Prim’s Algorithm Starting from A B 5 Select the shortest edge from a connected

Prim’s Algorithm Starting from A B 5 Select the shortest edge from a connected vertex to an unconnected vertex C 3 4 6 8 AB 3 8 A D F 7 5 4 2 E

Prim’s Algorithm B 5 Select the shortest edge from a connected vertex to an

Prim’s Algorithm B 5 Select the shortest edge from a connected vertex to an unconnected vertex C 3 4 6 8 AE 4 8 A D F 7 5 4 2 E

Prim’s Algorithm B 5 Select the shortest edge from a connected vertex to an

Prim’s Algorithm B 5 Select the shortest edge from a connected vertex to an unconnected vertex C 3 4 6 8 ED 2 8 A D F 7 5 4 2 E

Prim’s Algorithm B 5 Select the shortest edge from a connected vertex to an

Prim’s Algorithm B 5 Select the shortest edge from a connected vertex to an unconnected vertex C 3 4 6 8 DC 4 8 A D F 7 5 4 2 E

Prim’s Algorithm B 5 Select the shortest edge from a connected vertex to an

Prim’s Algorithm B 5 Select the shortest edge from a connected vertex to an unconnected vertex C 3 4 6 8 EF 5 8 A D F 7 5 4 2 E

Prim’s Algorithm B All vertices have been connected. 5 C 3 4 6 8

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

Some points to note • Both algorithms will always give solutions with the same

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.