Given a connected, undirected, and weighted graph with V
vertices and E
edges, the goal is to find a Minimum Spanning Tree (MST). A Minimum Spanning Tree is a subset of the edges that connects all the vertices with the minimum possible total edge weight and without forming any cycles.
Prim's Algorithm helps us construct this MST by starting from a node and greedily choosing the next lightest edge that connects a visited node to an unvisited node.
Sometimes, the problem may also ask to return the MST edges themselves (i.e., a list of edge pairs {u, v}
included in the MST).