![prim algorithm prim algorithm](https://image1.slideserve.com/1904369/prim-s-algorithm5-l.jpg)
The key value of vertex 5 and 8 are updated.
#Prim algorithm update
Update the key values of adjacent vertices of 6. Step 1: The set mstSet is initially empty and keys assigned to vertices are. Let us understand with the following illustration: The key values are used only for vertices that are not yet included in MST, the key value for these vertices indicates the minimum weight edges connecting them to the set of vertices included in MST. The idea of using key values is to pick the minimum weight edge from the cut. For every adjacent vertex v, if the weight of edge u-v is less than the previous key value of v, update the key value as the weight of u-v To update the key values, iterate through all adjacent vertices. The prims algorithm starts from any node and then adds any adjacent node whose. Update the key value of all adjacent vertices of u. Prims algorithm is used to find the minimum spanning tree of a graph.Pick a vertex u which is not there in mstSet and has a minimum key value.While mstSet doesn’t include all vertices.Assign the key value as 0 for the first vertex so that it is picked first. Assign a key value to all vertices in the input graph.Create a set mstSet that keeps track of vertices already included in MST.
![prim algorithm prim algorithm](https://i.ytimg.com/vi/J8WZry-r-cc/maxresdefault.jpg)
Follow the given steps to find MST using Prim’s Algorithm: And they must be connected with the minimum weight edge to make it a Minimum Spanning Tree. So the two disjoint subsets (discussed above) of vertices must be connected to make a Spanning Tree. The idea behind Prim’s algorithm is simple, a spanning tree means all vertices must be connected.
![prim algorithm prim algorithm](https://www.codesdope.com/staticroot/images/algorithm/prim10.png)