150 likes | 398 Views
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.
E N D
Prims Algorithmfor 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.
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
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
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
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
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
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
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
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
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
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