Prim's Algorithm

The Steps For Implementing Prim's Algorithm

  1. Determine the arbitrary starting point
  2. For each edge coming out of the node, add it to a priority queue based on weight
  3. While the priority queue is not empty, remove the edge with the least weight
  4. If the end node of the edge has not yet been visited, mark it as visited and add the edge to the tree
  5. If the step above was completed(meaning the end node hadn't been visited before), insert all outgoing edges from the current node to unvisited nodes
  6. Repeat the above 2 steps until the priority queue is empty

Link for More on Prim's and Example