Write Prim's Algorithm.
Ans: Prim's algorithm to find out a minimum spanning tree from a weighted graph in step by step form is given below.
Let G = (V, E) be graph and S = (VS, ES) be the spanning tree to be found from G.
Step 1: Choose a vertex v1 of V and initialize
VS = {v1} and
ES
= {}
Step 2: Choose a nearest neighbor of vi from V that is adjacent to some vj∈VS and that edge (vi, vj) does not form a cycle with members edge of ES. Set
VS = VS ∪{vi} and
ES = ES ∪{(vi, vj)}
Step 3: Again Repeat step2 until |Es| = |V| - 1.