Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prims Algorithm for finding a minimum spanning tree

Similar presentations


Presentation on theme: "Prims Algorithm for finding a minimum spanning tree"— Presentation transcript:

1 Prims Algorithm for finding a minimum spanning tree
115 90 52 35 45 40 55 20 110 100 120 32 50 60 88 38 30 25 A 70 70 Starting at vertex A, choose the edge of least weight. Your choices are shown in green.. The edge with least weight 25 will be the first edge in the tree.

2 From now on, the tree will be marked in blue
From now on, the tree will be marked in blue. Consider all edges with one end in the blue tree so far and one end outside. Your choices are in green. Choose the one of least weight and add it to the tree. That is the edge marked with weight 30. 115 90 52 35 45 40 55 20 110 100 120 32 50 60 88 38 30 25 A 70 70

3 Consider all edges with one end in the blue tree so far and one end outside. Your choices are in green. Notice that one edge of weight 70 now has both ends in the tree, so it is no longer a choice. Choose the one of least weight and add it to the tree. The least weight edge is marked with 50. 115 90 52 35 45 40 55 20 110 100 120 32 50 60 88 38 30 25 A 70 70

4 Consider all edges with one end in the blue tree so far and one end outside. Your choices are in green. As we continue adding edges to the tree, some green edges are changed back to black because they have both ends in the tree. Choose the one of least weight and add it to the tree. The least weight edge is marked with 40. 115 90 52 35 45 40 55 20 110 100 120 32 50 60 88 38 30 25 A 70 70

5 Consider all edges with one end in the blue tree so far and one end outside. Your choices are in green. Choose the one of least weight and add it to the tree. The least weight edge is marked with 55. 115 90 52 35 45 40 55 20 110 100 120 32 50 60 88 38 30 25 A 70 70

6 Consider all edges with one end in the blue tree so far and one end outside. Your choices are in green. Choose the one of least weight and add it to the tree. The least weight edge is marked with 70. 115 90 52 35 45 40 55 20 110 100 120 32 50 60 88 38 30 25 A 70 70

7 Consider all edges with one end in the blue tree so far and one end outside. Your choices are in green. Choose the one of least weight and add it to the tree. The least weight edge is marked with 38. 115 90 52 35 45 40 55 20 110 100 120 32 50 60 88 38 30 25 A 70 70

8 Consider all edges with one end in the blue tree so far and one end outside. Your choices are in green. Choose the one of least weight and add it to the tree. The least weight edge is marked with 20. 115 90 52 35 45 40 55 20 110 100 120 32 50 60 88 38 30 25 A 70 70

9 Consider all edges with one end in the blue tree so far and one end outside. Your choices are in green. Choose the one of least weight and add it to the tree. The least weight edge is marked with 32. 115 90 52 35 45 40 55 20 110 100 120 32 50 60 88 38 30 25 A 70 70

10 Consider all edges with one end in the blue tree so far and one end outside. Your choices are in green. Choose the one of least weight and add it to the tree. The least weight edge is marked with 35. 115 90 52 35 45 40 55 20 110 100 120 32 50 60 88 38 30 25 A 70 70

11 Done! Now the blue tree contains all the vertices of the graph, so it is a spanning tree. The total weight is: 395 115 90 52 35 45 40 55 20 110 100 120 32 50 60 88 38 30 25 A 70 70


Download ppt "Prims Algorithm for finding a minimum spanning tree"

Similar presentations


Ads by Google