![]() 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. Update the key value of all adjacent vertices of u.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.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. ![]() ISRO CS Syllabus for Scientist/Engineer Exam.ISRO CS Original Papers and Official Keys.GATE CS Original Papers and Official Keys. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |