Prim's Algorithm

An approach that we could follow to obtain the minimum spanning tree.

  1. Create an array or a min heap named 'visited'.
  2. Select one node and add it to 'visited'.
  3. Select one minimum weighted edge that is connected to the selected node.
  4. Add the node to 'visited' which is connected to the selected edge.
  5. Select a minimum weighted edge that connects one node that is in 'visited' and another node that is not in 'visited'.
  6. Repeat step 4 and 5 until all nodes are in 'visited'.

more important info