Start from some arbitrary start node.
It is important to note that MST is not unique.
Why does Prim’s work? Special case of generic algorithm.
This is one algorithm to find a MST from a Graph. It is as follows:
Essentially, this algorithm runs via the same mechanism as Dijkstra's algorithm, but while Dijkstra's considers candidate nodes by their distance from the source node, Prim's looks at each candidate node's distance from the MST under construction.
Thus, the runtime of Prim's if done using the same mechanism as Dijkstra's, would be the same as Dijkstra's, which is
Remember, this is because we need to add to a Priority Queue fringe once for every edge we have, and we need to dequeue from it once for every vertex we have.