Minimum Spanning Trees

COMP2521 20T2 ♢ Minimum Spanning Trees [0/15]
❖ Minimum Spanning Trees

Reminder: Spanning tree ST of graph G=(V,E)

Minimum spanning tree MST of graph G Applications:
COMP2521 20T2 ♢ Minimum Spanning Trees [1/15]
❖ ... Minimum Spanning Trees


Example:


[Diagram:Pics/mst-example.png]

COMP2521 20T2 ♢ Minimum Spanning Trees [2/15]
❖ ... Minimum Spanning Trees


Problem: how to (efficiently) find MST for graph G ?

One possible strategy:


Note that MST may not be unique
COMP2521 20T2 ♢ Minimum Spanning Trees [3/15]
❖ ... Minimum Spanning Trees

Brute force solution  (using generate-and-test strategy):

findMST(G):
|  Input  graph G
|  Output a minimum spanning tree of G
|
|  bestCost=∞
|  for all spanning trees t of G do
|  |  if cost(t) < bestCost then
|  |     bestTree=t
|  |     bestCost=cost(t)
|  |  end if
|  end for
|  return bestTree

Not useful in general because #spanning trees is potentially large
(e.g. nn-2  for a complete graph with n  vertices)

COMP2521 20T2 ♢ Minimum Spanning Trees [4/15]
❖ ... Minimum Spanning Trees


Simplifying assumption:


If edges are not weighted
Our MST algorithms apply to
COMP2521 20T2 ♢ Minimum Spanning Trees [5/15]
❖ Kruskal's Algorithm


One approach to computing MST for graph G with V  nodes:

  1. start with empty MST
  2. consider edges in increasing weight order
    • add edge if it does not form a cycle in MST
  3. repeat until V-1 edges are added

Critical operations:
COMP2521 20T2 ♢ Minimum Spanning Trees [6/15]
❖ ... Kruskal's Algorithm

Execution trace of Kruskal's algorithm:

[Diagram:Pics/kruskal-trace.png]

COMP2521 20T2 ♢ Minimum Spanning Trees [7/15]
❖ ... Kruskal's Algorithm

Pseudocode:

KruskalMST(G):
|  Input  graph G with n nodes
|  Output a minimum spanning tree of G
|
|  MST=empty graph
|  sort edges(G) by weight
|  for each e ∈ sortedEdgeList do
|  |  MST = MST ∪ {e}  // add edge
|  |  if MST has a cyle then
|  |     MST = MST \ {e}  // drop edge 
|  |  end if
|  |  if MST has n-1 edges then
|  |     return MST
|  |  end if
|  end for

COMP2521 20T2 ♢ Minimum Spanning Trees [8/15]
❖ ... Kruskal's Algorithm

Rough time complexity analysis …

Possibilities for cycle checking:
COMP2521 20T2 ♢ Minimum Spanning Trees [9/15]
❖ Prim's Algorithm

Another approach to computing MST for graph G=(V,E):

  1. start from any vertex v and empty MST
  2. choose edge not already in MST to add to MST;  must be:
    • incident on a vertex s  already connected to v  in MST
    • incident on a vertex t  not already connected to v  in MST
    • minimal weight of all such edges
  3. repeat until MST covers all vertices

Critical operations:
COMP2521 20T2 ♢ Minimum Spanning Trees [10/15]
❖ ... Prim's Algorithm

Execution trace of Prim's algorithm (starting at s=0):

[Diagram:Pics/prim-trace.png]

COMP2521 20T2 ♢ Minimum Spanning Trees [11/15]
❖ ... Prim's Algorithm

Pseudocode:

PrimMST(G):
|  Input  graph G with n nodes
|  Output a minimum spanning tree of G
|
|  MST=empty graph
|  usedV={0}
|  unusedE=edges(g)
|  while |usedV| < n do
|  |  find e=(s,t,w) ∈ unusedE such that {
|  |     s ∈ usedV ∧ t ∉ usedV 
|  |       ∧ w is min weight of all such edges
|  |  }
|  |  MST = MST ∪ {e}
|  |  usedV = usedV ∪ {t}
|  |  unusedE = unusedE \ {e}
|  end while
|  return MST

Critical operation:  finding best edge

COMP2521 20T2 ♢ Minimum Spanning Trees [12/15]
❖ ... Prim's Algorithm


Rough time complexity analysis …

Note:
COMP2521 20T2 ♢ Minimum Spanning Trees [13/15]
❖ Sidetrack: Priority Queues


Some applications of queues require

Priority Queues (PQueues) provide this via: Will discuss priority queues in more detail in another video
COMP2521 20T2 ♢ Minimum Spanning Trees [14/15]
❖ Other MST Algorithms

Boruvka's algorithm ... complexity O(E·log V)

Karger, Klein, and Tarjan ... complexity O(E)
COMP2521 20T2 ♢ Minimum Spanning Trees [15/15]


Produced: 4 Jul 2020