1 / 20

Decision Maths

Decision Maths. Networks Prim’s Algorithm. Prim`s Algorithm. In Lesson 1 we learnt about Kruskal`s algorithm, which was used to solve minimum connector problems. Another method that can be used is Prim`s algorithm. Step 1 – Select any node Step 2 – Connect it to the nearest node

duman
Download Presentation

Decision Maths

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Decision Maths Networks Prim’s Algorithm

  2. Prim`s Algorithm • In Lesson 1 we learnt about Kruskal`s algorithm, which was used to solve minimum connector problems. • Another method that can be used is Prim`s algorithm. • Step 1 – Select any node • Step 2 – Connect it to the nearest node • Step 3 – Connect one node already selected to the nearest unconnected node. • Step 4 – Repeat 3 until all nodes are connected.

  3. Prim`s Algorithm • Consider the example we looked at last lesson. • Select any node you like. • Lets select F.

  4. Prim`s Algorithm • Connect it to the nearest node. • C and D are both 3 away so we can choose either. • Lets select C.

  5. Prim`s Algorithm • The nearest node to either of F or C is D, which is only 3 away from F. • So connect D to F.

  6. Prim`s Algorithm • The nearest to D, F or C is E which is 2 from D. • So connect E to D.

  7. Prim`s Algorithm • The nearest to any of these four nodes is A which is 5 away from F. • Connect A to F.

  8. Prim`s Algorithm • We now need to connect the last node, B. • The shortest arc is AB, which is 2. • Connect B to A.

  9. Prim`s Algorithm • All the nodes are now connected so this is the minimum connector or minimal spanning tree.

  10. Distance Table • The Network can also be represented as a table. • The infinity symbol (∞) means there is no edge between the two nodes.

  11. Prim`s on a Distance Table • We are going to apply Prim`s algorithm to the distance table. • This demonstrates how a computer could apply the algorithm. • Prim`s is more suitable than Kruskal`s as computers have a problem recognising loops. • As you go through the algorithm, see if you can relate the procedure to the last example.

  12. Prim`s on a Distance Table • Step 1 – Select any arbitrary node. • Step 2 – Delete the row and loop the column that correspond to the node selected. • Step 3 – Choose the smallest number in the loop. • Step 4 – Delete the row that this smallest number is in. • Step 5 – Loop the column that corresponds to the row just deleted. • Step 6 – Choose the smallest number in any loop. • Step 7 – Repeat steps 4, 5 and 6 until all rows have been deleted and columns looped.

  13. Here I have chosen F. Delete the row. Loop the column. Select the smallest number in the loop. Prim`s on a Distance Table

  14. Delete row C. Loop column C. Select the smallest number in any loop that is not crossed out. Prim`s on a Distance Table

  15. Delete row D. Loop column D. Select the smallest number in any loop that is not crossed out. Prim`s on a Distance Table

  16. Delete row E. Loop column E. Select the smallest number in any loop that is not crossed out. Prim`s on a Distance Table

  17. Delete row A. Loop column A. Select the smallest number in any loop that is not crossed out. Prim`s on a Distance Table

  18. Delete row B. Loop column B. Prim`s on a Distance Table

  19. Prim`s on a Distance Table • The algorithm is complete when all the columns have been looped and the rows crossed out. • The circles show the edges in the minimum connector.

  20. Prim`s on a Distance Table • In this case they are AB, DE, AF, CF, DF • Can you explain why this procedure is exactly the same as applying Prim`s algorithm?

More Related