Prims Algorithm
From Rice Wiki
Approach: Greedy
Implementation
for each u in V:
key[u] = infinity // cost array
pi[u] = infinity // from array
Q = new PriorityQueue(V)
key[root] = 0
while Q is not empty:
u = extractMin(Q)
# Reduce nodes
for v in adj[u]:
if v in Q and w[u,v] < key[v]:
key[v] = w[u,v]
Analysis
Priority queue is slower than array when the graph is dense, so sometimes it's better to use Dijsktra's algorithm.
Proof: Greedy
Suboptimality
Given MST tree for the graph G
where the number of edges is Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle n - 1} , the weight of edges is minimum, and the tree is spanning.
Let Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle (x,y)} be a leaf edge in the tree.
