Minimum Spanning Tree Problem

  • Th problem is to find a minimum spanning tree for a connected undirected graph with weights on the edges. (the weights are non-negative)

Prim’s Algorithm

for each v ∈ V:
  C[v] = ∞ # the cheapest cost of a connection to v
  E[v] = null # the edge that connects v to the tree

initialize an empty forest F
initialize a set Q = V # vertices not yet in F

while Q ≠ ∅:
  u = the vertex in Q with the smallest C[u]
  remove u from Q
  add u to F
  for each neighbor v of u:
    if v ∈ Q and w(u, v) < C[v]:
      C[v] = w(u, v)
      E[v] = (u, v)

return F, which specifically includes the corresponding edges in E
  • A cut of a graph is a partition of into two sets and .
    • An edge crosses the cut if and .
    • A cut respects a set of edges if no edge in crosses the cut.
    • An edge is a light edge crossing a cut if its weight is the minimum of all the weights of the edges crossing the cut.
      • (More generally, an edge is a light edge satisfying a given property if its weight is the minimum of all the weights of the edges satisfying that property.)
  • An edge is safe for a set of edges that is a subset of some MST if is also a subset of some MST.
  • Theorem: Let be a subset of that is included in some MST for , and let be any cut of that respects .
    • Let be a light edge crossing . Then is safe for .
      • If is an unique light edge, then is in every MST of .