Spanning Tree

Definition (Cut)

A cut is a partition of the nodes into two nonempty subsets and

The cutset of a cut is the set of edges with exactly one endpoint in (removing the cutset would disconnect the partitions).

Claim

A cycle and a cutset intersect in an even number of edges.

Definition (Spanning Tree)

Let be a subgraph of an undirected graph . is a spanning tree of if is both acyclic and connected.

If has edge costs, a minimum spanning tree is a spanning tree such that the sum of the edge costs in is minimized.

Theorem (Cayley's Theorem)

A graph with nodes has spanning trees

Greedy Algorithm

Fundamental Cycles

  • Fundamental Cycle
    • Let be a spanning tree of ).
    • For any non tree-edge , contains a unique cycle, say , the fundamental cycle.
    • For any edge , is a spanning tree.
  • Fundamental Cutset
    • Let be a spanning tree of .
    • For any tree edge , has two connected components.
    • Let denote corresponding cutset
    • For any edge , is a spanning tree
  • Observation: If then is not an MST

Algorithm

  • Rules
    • Red rule
      • Let be a cycle with no red edges
      • Select an uncolored edge of of max cost and color it red
    • Blue rule
      • Let be a cutset with no blue edges
      • Select an uncolored edge in of min cost and color it blue
  • Algorithm
    • Apply the red and blue rules (nondeterministically) until all edges are colored. The blue edges form an MST.
    • Note: can stop once edges are colored blue

Correctness

Claim (Color Invariant)

There exists an MST containing every blue edge and no red edge

Proof: Base Case: No edges colored every MST contains every blue edge and excludes every red edge (since there are none of either)

Inductive Hypothesis: Assume color invariant when edges colored for some

Inductive Step: edges colored Case 1: Blue rule applied next

  • Let be chosen cutset, and let be edge colored blue.
  • If , then still satisfies invariant.
  • Otherwise, consider fundamental cycle by adding to .
  • Let be another edge in .
  • is uncolored and since
    • not red
    • Blue rule not blue and
  • Thus, satisfies invariant.

Case 2: Red rule applied next

  • Let be chosen cycle, and be edge colored red.
  • If , then still satisfies invariant.
  • Otherwise, consider fundamental cutset by deleting from .
  • Let be another edge in . is uncolored and since
    • not blue
    • red rule not red and
  • Thus, satisfies invariant

Theorem

The greedy algorithm terminates. Blue edges form an MST.

Proof: We need to show that either the red or blue rule (or both) applies.

  • Suppose edge is left uncolored.
  • Blue edges form a forest.
  • Case 1: Both endpoints of are in the same blue tree.
    • Apply red rule to cycle formed by adding to blue forest.
  • Case 2: both endpoints of are in different blue trees.
    • Apply blue rule to cutset induced by either of two blue trees.

Prim’s Algoritm

Algorithm

  • Initialize for any node ,
  • Repeat times
    • Add to a min-cost edge with exactly one endpoint in
    • Add the other endpoint to .

Correctness

Theorem

Prim’s algorithm computes an MST

Proof: Special case of greedy algorithm (blue rule repeatedly applied to S)

Time Complexity

  • using arrays
  • using priority queues

Kruskal’s Algoritm

Algorithm

  • Arrange edges by ascending weights
  • Add edges to the the spanning tree as long as they don’t create a cycle using Cycle Detection

Correctness

Theorem

Kruskal’s algorithm computes an MST.

Proof: Special case of greedy algorithm. Case 1: Both endpoints of are in the same blue tree

  • Color red by applying red rule to unique cycle (all other edges in cycle are blue) Case 2: Both endpoints of are in different blue trees
  • Color blue by applying blue rule to cutset defined by either tree (no edge in cutset has smaller cost because Kruskal’s chose it first)

Time complexity

  • Using Disjoint Set Cycle Detection: