~/ learn/ comp-372/ cards/ Prim's algorithm
1 of 4

Type the CLRS MST-PRIM pseudocode

Type the CLRS MST-PRIM pseudocode

Answer

for each u in G.V: u.key = INF; u.pi = NIL r.key = 0 Q = G.V # min-priority queue on key while Q is not empty: u = EXTRACT-MIN(Q) for each v in G.Adj[u]: if v in Q and w(u, v) < v.key: v.pi = u DECREASE-KEY(Q, v, w(u, v))

EXTRACT-MIN commits the lightest edge crossing the cut (tree vs non-tree) — safe by Corollary 21.2. The relaxation loop keeps each v.key equal to the lightest edge from v to the growing tree.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/6d5f35e3-d1af-4fe7-892b-7485e9db3edc/flashcard utf-8 LF