Min Spanning

Embed Size (px)

Citation preview

  • 8/12/2019 Min Spanning

    1/34

    Subhash Suri UC Santa Barbara

    Minimum Spanning Trees

    Given an undirected graph G= (V, E),with edge costs cij.

    A spanning tree T of G is a cycle-freesubgraph that spans all the nodes.

    The cost of T is the sum of the costs ofthe edges in T.

    MST is the smallest cost spanning tree.

    a

    b c

    e

    d

    f

    g

    5

    32

    12

    16

    4

    a

    b c

    e

    d

    f

    g

    8 5

    3

    14

    102

    18

    12 3016

    264

    Graph G MST

  • 8/12/2019 Min Spanning

    2/34

    Subhash Suri UC Santa Barbara

    Applications of MST

    a

    b c

    e

    d

    f

    g

    5

    32

    12

    16

    4

    a

    b c

    e

    d

    f

    g

    8 5

    3

    14

    102

    18

    12 3016

    264

    Graph G MST

    Direct applications: interconnection ofentities.

    1. electrical devices (circuit boards)2. utilities (gas, oil)3. computers or communication devices by

    high speed lines.4. cable service customers

    Indirect applications.

    1. Optimal message passing.2. Data storage.3. Cluster analysis

  • 8/12/2019 Min Spanning

    3/34

    Subhash Suri UC Santa Barbara

    Optimality Conditions

    Greedy incremental flavor: add one edgeat a time.

    Each step colors an edge of G blue(accept) orred (reject).

    ColorInvariant (CI): MST containingall blue edges, and no red edges.

    Recall that a cut in G= (V, E) is apartition of it vertices (X, V X).

  • 8/12/2019 Min Spanning

    4/34

    Subhash Suri UC Santa Barbara

    Blue and Red Rules

    x y

    x

    y

    Cut Rule (Blue) Red Rule (Cycle)

    Blue (Cut) Rule: Select a cut not crossed byany blue edge. Among the uncolored edgescrossing the cut, make the minimum cost

    edge blue.

    Red (Cycle) Rule: Select a simple cycle with

    no red edges. Among all uncolored edges of the cycle, make the maximum cost one red.

  • 8/12/2019 Min Spanning

    5/34

    Subhash Suri UC Santa Barbara

    Generic MST Algorithm

    Theorem: Apply red and blue rules inarbitrary order until neither rule applies.

    The resulting set of blue edges forms a MST.

    a

    b c

    e

    d

    f

    g

    5

    32

    12

    16

    4

    a

    b c

    e

    d

    f

    g

    8 5

    3

    14

    102

    18

    12 3016

    264

    Graph G MST

    Proof has two parts:

    1. The Color Invariant (CI) holds.

    2. All edges are ultimately colored.

  • 8/12/2019 Min Spanning

    6/34

    Subhash Suri UC Santa Barbara

    Correctness of Blue Rule

    Let T be the MST guaranteed by the CIbefore the last coloring step.

    ee

    e

    MST T*

    MST satisfyingcolor invariant

    Cut

    Suppose the last step was to color e blue.Consider the cut (X, V X) to which bluerule applied. Some edge e of T mustcross this cut.

    The graph T + e contains a cycle

    containing both e and e, andcost(e)cost(e). (Why?)

    So T + e e is also a MST.

  • 8/12/2019 Min Spanning

    7/34

    Subhash Suri UC Santa Barbara

    Correctness of Red Rule

    MST T*

    MST satisfyingcolor invariant

    e

    Cycle

    e

    e

    Suppose edge e colored red. If eT, thenT still satisfies CI. Otherwise, consider

    T e. It has two components.

    The cycle used in coloring e has some edgee with one end in each of thesecomponents.

    By choice, cost(e

    )cost(e). Thus, the treeT e + e is also an MST.

  • 8/12/2019 Min Spanning

    8/34

    Subhash Suri UC Santa Barbara

    Proof of Completion

    Blue edges form a forest.

    Suppose edge e left uncolored, and neitherrule applies.

    If both endpoints ofe in same blue tree B,

    then red rule applies to the cycle B+ e.

    If endpoints in different blue trees B1, B2,then blue rule applies across the cutseparating B1 and B2.

    Thus, the generic MST algorithm iscorrect.

  • 8/12/2019 Min Spanning

    9/34

    Subhash Suri UC Santa Barbara

    Prims Algorithm

    Start at any node s, and set T ={s}.

    repeat n 1 times

    Let T be the current tree.Choose a minimum cost uncolored

    (u, v) with uT and vT.Color (u, v) blue, and add v to T.

    b

    a

    b c

    e

    d

    f

    g

    8 5

    3

    14

    102

    1812 30

    16

    264

    a

    c

    d

    5

    32

    Graph GAfter 3 steps.

  • 8/12/2019 Min Spanning

    10/34

    Subhash Suri UC Santa Barbara

    Prims Algorithm

    1. Input: Graph G= (V, E). For each vertexv, A(v) is list of its neighbors.

    2. key(w) is the cost of the cheapest edge(v, w) with vT. blue(v, w) is the identityof this edge.

    3. Initialize:

    key(v) =, for all vV. H=makeHeap(). v=s.

    4. while v=N IL do

    for wA(v) ifcost(v, w)< key(w) key(w) =cost(v, w) blue(w) = (v, w) if wH insert(w,H,key(w)) else DecreaseKey(w,H,key(w)) end for v=ExtractMin(H).

  • 8/12/2019 Min Spanning

    11/34

    Subhash Suri UC Santa Barbara

    Illustration

    b

    a

    c

    d

    5

    32

    a

    b c

    e

    d

    f

    g

    5

    32

    12

    b c

    e

    d

    f

    g

    8 5

    3

    14

    102

    18

    12 3016

    264

    b c

    e

    d

    f

    g

    5

    32

    12

    16

    4

    a a

    After 3 steps

    After 4 steps Final MST

  • 8/12/2019 Min Spanning

    12/34

    Subhash Suri UC Santa Barbara

    Illustration

    b

    a

    c

    d

    5

    32

    a

    b c

    e

    d

    f

    g

    8 5

    3

    14

    102

    18

    12 3016

    264

    After 3 steps

    b c

    e

    d

    f

    g

    5

    32

    12

    a

    Blue edges and keys after 3 steps

    14

    16

  • 8/12/2019 Min Spanning

    13/34

    Subhash Suri UC Santa Barbara

    Kruskals Algorithm

    Initially make each node of V a singletontree.

    Scan edges ofE in non-decreasing order ofcost.

    scan edge e:

    If both endpoints of e in the sametree, color it red. Otherwise color eblue, and merge the two trees.

  • 8/12/2019 Min Spanning

    14/34

    Subhash Suri UC Santa Barbara

    Illustration

    a

    b c

    e

    d

    f

    g

    8 5

    3

    10

    2

    12

    4

    a

    b c

    e

    d

    f

    g

    5

    32

    4

    a

    b c

    e

    d

    f

    g

    8 5

    3

    14

    102

    18

    12 3016

    264

    8, 10 colored red. 12 colored blue

    After 4 edges scanned

    a

    b c

    e

    d

    f

    g

    5

    32

    12

    4

    16

    Final MST

  • 8/12/2019 Min Spanning

    15/34

    Subhash Suri UC Santa Barbara

    Complexity Results

    Heap implementation of Prim: O(m log2 n).

    d-Heap: O(nd logd n + m logd n).

    Fibonacci Heap: O(m + n log n).

    Kruskal with Union-Find:O(m log n + m(n)).

    Round-Robin: O(m log log n).

    Latest theoretical bound: O(m(n)).

  • 8/12/2019 Min Spanning

    16/34

    Subhash Suri UC Santa Barbara

    Balancing MST and SP

    10

    s

    10 15

    a

    1010

    b

    c10

    s

    10

    a

    10

    b

    c

    s

    10 15

    a

    10

    b

    c

    Graph G MST SPT

    MST minimizes total interconnectioncost.

    SPT minimizes individual path lengths,from a root source.

    How does each do with the other costmetric?

    In Fig. 2, dmst(a, c) = 20, but dspt(a, c) = 15.

    In Fig. 3, cost(spt) = 35, but cost(mst) = 30.

  • 8/12/2019 Min Spanning

    17/34

    Subhash Suri UC Santa Barbara

    A Pathological Example

    ..

    .

    1

    1

    1

    2

    1

    M MM

    1

    1

    1

    1

    1

    1 1

    1

    M

    MM

    M

    M

    (i) (ii)

    a

    z

    Fig. (i) shows an example wheredmst(a, z) =n, while dspt= 2.

    As n , this ratio is unbounded.

    Fig. (ii) shows an example where

    cost(spt) =nM, while cost(mst) =n 1 + M.

    As M , this ratio is unbounded.

  • 8/12/2019 Min Spanning

    18/34

    Subhash Suri UC Santa Barbara

    Balanced Tree Theorem

    Theorem: Pick any constant >1, and let= 1 + 2

    1. Given G= (V, E) and a node s,there always exists a spanning tree T rooted

    at s such that

    dT(s, v) dspt(s, v), for any vV.

    cost(T) cost(M ST).

    .

    .

    .

    1

    1

    1

    2

    1

    M MM

    1

    1

    1

    1

    1

    1 1

    1

    M

    M

    M M

    M

    (i) (ii)

    a

    z

    Which T for these pathological cases?

  • 8/12/2019 Min Spanning

    19/34

    Subhash Suri UC Santa Barbara

    Pre-Order Numbering

    Pre-Order Lemma: Let T be a spanning treewith root s. Let z0, z1, . . . , zk be any k+ 1nodes listed in their pre-order sequence.

    Then,k

    i=1dT(zi1, zi) 2cost(T).

    6

    1

    3

    2

    4

    5 7

    8 9

    1312

    1110

    Draw T in the plane. Let W be thedoubling walk around T (pre-order).

    Each edge visted twice, cost(W) = 2cost(T).

  • 8/12/2019 Min Spanning

    20/34

    Subhash Suri UC Santa Barbara

    Proof

    6

    1

    3

    2

    4

    5 7

    8 9

    1312

    1110

    dT(u, v) is tree path length.

    Due to pre-ordering, firstoccurrence of

    zi1 is beforethat of zi.

    Mark off portions of W that join firstoccurence of zi1 to that of zi.

    No edge of W marked more than once.

    Thus,ki=1

    dT(zi1, zi) cost(W) 2cost(T).

  • 8/12/2019 Min Spanning

    21/34

    Subhash Suri UC Santa Barbara

    Algorithm

    = 1 + 21. E.g. = 2, = 3.

    Compute MST and its pre-order numbers,starting with s.

    Compute dspt(s, v), for all v.

    Initialize H=M ST.

    for each node v in pre-order doif dH(s, v)> dspt(s, v) thenadd to H all edges of path Pspt(s, v).

    Output SPT of H, rooted at s.

    16

    4

    7

    8

    5

    2

    3

    s=1

    10

    10

    10

    10

    15

    15

    10

    5

    6

    5

    10

    4

    7

    8

    5

    2

    3

    s=1

    10

    10

    10

    10

    15

    15

    10

    5

    6

    5

    10

    Graph G MST

    16

  • 8/12/2019 Min Spanning

    22/34

    Subhash Suri UC Santa Barbara

    Illustration

    16

    4

    7

    8

    5

    2

    3

    s=1

    10

    10

    10

    10

    15

    15

    10

    5

    6

    5

    10

    4

    7

    8

    5

    2

    3

    s=1

    10

    10

    10

    10

    15

    15

    10

    5

    6

    5

    10

    4

    7

    8

    5

    2

    3

    s=

    10

    10

    10

    10

    15

    15

    10

    5

    6

    5

    10

    4

    7

    8

    5

    2

    3

    s=1

    10

    10

    10

    15

    5

    6

    10

    MST (1,5) added

    (1,6) added Final tree T output

    16 16

    16

  • 8/12/2019 Min Spanning

    23/34

    Subhash Suri UC Santa Barbara

    Analysis

    T satisfies dT(s, v) dspt(s, v); algorithmadds SP whenever needed.

    Let z0, z1, . . . , zk be the pre-order sequenceof vertices that caused SP edges to beadded to H.

    When zi is examined, H contains theshortest path to zi1. So, we must have

    dspt(s, zi1) + dmst(zi1, zi) > dspt(s, zi).

    Sum these over all i:

    dspt(s, z1) dspt(s, z0) < dmst(z0, z1)

    dspt(s, z2) dspt(s, z1) < dmst(z1, z2)

    ...

    dspt(s, zk) dspt(s, zk1) < dmst(zk1, zk)

    k

    i=1( 1)dspt(s, zi)0,

    Ev =ki=1

    w(ei) < 2w(M ST)

    t 1 .

  • 8/12/2019 Min Spanning

    34/34

    Spanner Results

    Althofer et al. result gives spanners with

    O(n1+ 2t1) edges.

    Peleg-Schaffer shows that there aren-vertex graphs, whose all t-spannerscontain (n1+

    1t ) edges.

    Much better results know if distances areEuclidean.

    In Euclidean k-space (constant k)spanners with O(n) edges exist for anyconstant stretch factors t.

    Such spanners possible with O(M ST)weight, O(1) degree, O(log n) diameter.