EMIS 8374

1 / 33

# EMIS 8374 - PowerPoint PPT Presentation

EMIS 8374. Optimal Trees updated 25 April 2006. Minimum Spanning Tree (MST). Input A (simple) graph G = (V,E) Edge cost c ij for each edge e  E Optimization Problem Find a minimum-cost spanning tree

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' EMIS 8374' - valentine-reilly

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### EMIS 8374

Optimal Trees

updated 25 April 2006

Minimum Spanning Tree (MST)
• Input
• A (simple) graph G = (V,E)
• Edge cost cij for each edge e  E
• Optimization Problem
• Find a minimum-cost spanning tree
• Spanning tree: a set of |V|-1 edges T such that each vertex is incident to at least one edge in T, and T contains no cycles.
MST Example: Some Feasible Spanning Trees

6

6

3

3

2

2

3

3

5

cost = 17

1

1

7

cost = 16

1

2

5

5

4

4

6

3

3

2

2

cost = 14

cost = 16

4

1

1

7

7

1

1

2

2

5

5

4

4

1

3

2

5

4

5

4

7

MST Optimality Conditions: Path Optimality

c25 > c12

c25 > c15

6

c34 > c23

c34 > c12

c34 > c15

c34 > c45

3

1

2

c24 > c12

c24 > c15

c24 > c45

Path Optimality Condition
• A spanning tree T is a minimum spanning tree if and only for every out-of-tree edge (i,j), cij cuv for every in-tree edge (u,v) on the path from i to j in T .
• This is clearly a necessary condition for a MST. If an out-of-tree edge (i, j) has a lower cost than any in-tree edge (u,v) on the path from i to j in T, then we can improve T by replacing edge (u,v) with edge (i, j).

1

3

2

5

4

Path Optimality: Necessity

6

3

5

1

2

Replacing in-tree edge (2,4) with out-of-tree edge (4,5) would decrease the cost of this tree. Therefore, it cannot be optimal.

1

3

2

5

4

c25 >c12

c24 > c12

c45 > c12

3

5

4

7

MST Optimality Conditions: Cut Optimality

6

1

2

Removing an in-tree edge (u,v) creates a cut in the tree.

For any out-of-tree edge (i,j) crossing the cut cij cuv.

Cut Optimality
• Given a spanning tree T, let C[u,v] be the set of edges in the cut formed by removing in-tree edge (u, v) from T.
• A spanning tree T is a MST if and only if every in-tree edge is a minimum cost edge in C[u,v].

1

3

2

5

4

3

Cut Optimality: Necessity

6

5

4

7

1

2

The in-tree edge (2, 4) is not a minimum cost edge in the cut formed by removing it from T.

If we remove in-tree edge (2, 4), we can restore connectivity by adding out-of-tree edge (4, 5).

1

3

2

5

4

5

3

1

Cut Optimality: Necessity

6

4

If we remove in-tree edge (2, 4), we can restore connectivity by adding out-of-tree edge (4, 5).

Since the resulting tree has a lower total cost, the first tree could not have been optimal.

Sufficiency of Cut and Path Optimality
• It is easy to see that any MST must satisfy the cut and path optimality conditions.
• If a tree T happens to satisfy these conditions, does that imply that T is a MST?
Sufficiency of Cut Optimality

4

4

2

2

G

T*

1

1

3

3

5

5

• Let T* be a MST of G.
• Suppose that TC satisfies the cut optimality condition.
• Show that TC is also a MST.

4

2

TC

1

3

5

Sufficiency of Cut Optimality

4

T*

2

Since T* is a MST, it must satisfy the path optimality condition.

So, c25 c24 (and c25 c45).

1

3

5

Since TC satisfies the cut optimality condition, c25 c24 (and c25 c35 ).

4

2

TC

This implies c25= c24.

1

Replacing (2,4) with (2,5) in T* creates a new MST, T**.

3

5

Sufficiency of Cut Optimality

4

T**

2

Since T** is a MST, it must satisfy the path optimality condition.

So, c23 c35 (and c23 c25).

1

3

5

Since TC satisfies the cut optimality condition, c23 c35 (and c25 c13 ).

4

2

TC

This implies c23= c35.

1

Replacing (3,5) with (2,3) in T** creates a new MST, T***.

3

5

Sufficiency of Cut Optimality

4

T***

2

Since TC is identical to T***, it is optimal.

1

This argument can be formalized to apply to the general case and show that any tree that satisfies the cut optimality condition must be optimal.

3

5

4

2

TC

1

Thus, cut optimality is a sufficient condition for a tree to be a MST.

3

5

Kruskal’s Algorithm (Path Optimality)
• F := E
• T := {}
• Repeat Until |T| = |V| - 1
• Begin
• Select (i,j)  F such that cij = min(cuv: (u,v)  F)
• F := F \ {(i,j)}
• If T  {(i,j)} does not contain a cycle then
• T := T  {(i,j)}
• End

Can be implemented in O(|E|+|V| log |V}) time plus the time for sorting the edges.

Testing for Cycles
• Let GT be the subgraph of G induced by the set of edges in T.
• As edges are added to T, the algorithm creates a forest (i.e., a collection of trees).
• Each tree in the forest forms a connected component of GT.
• By keeping track of which component each node is in, we can quickly, and easily determine whether or not adding a new edge to T will create a cycle.
Testing for Cycles

Initialize component[i] = 0 for all i  V.

When edge (i,j) is inspected, there are 5 cases to

• component[i] = component[j] = 0

Add (i,j) to T; (i,j) becomes a new component of GT.

• component[i] = 0, component[j] > 0.

Add (i,j) to T; vertex i will go into the same component as j.

• component[i] > 0, component[j] = 0.

Add (i,j) to T; vertex j will go into the same component as i.

• component[i] > 0, component[j] > 0, component[i]  component[j]

Add (i,j) to T; merge components.

• component[i] = component[j] > 0

Adding (i,j) would create a cycle.

1

4

2

3

5

Kruskal’s Algorithm: Example 2

2

4

1

2

2

5

3

1

6

2

1

2

(2, 3) creates a cycle because vertices 2 and 3 are in the same connected component.

1

4

2

3

5

Kruskal’s Algorithm: Example 2

2

4

1

2

2

5

3

1

6

2

1

2

(2, 4) does not create a cycle because vertices 2 and 4 are in different connected components.

1

4

2

3

5

Kruskal’s Algorithm: Example 2

2

4

2

2

2

5

3

1

6

2

2

2

Merge components 1 and 2.

Prim’s Algorithm (Cut Optimality)
• Choose any node v in V.
• S1 := {v}
• T := {}
• k := 1
• Repeat Until |T| = |V| - 1
• Begin
• Select a minimum cost edge (i,j) in the cut [Sk,V\{Sk}]
• T := T  {(i,j)}
• If i  Sk then Sk+1 := Sk {j}
• Else If j  Sk then Sk+1 := Sk {i}
• k := k+1
• End

Can be implemented in O(|E|+|V| log |V}) time.

1

4

2

3

5

Prim’s Algorithm

4

2

5

3

1

6

2

S1 = {3}

S2 = {1,3}

1

4

2

3

5

Prim’s Algorithm

4

2

5

3

1

6

2

S2 = {1,3}

S3 = {1, 2, 3}

1

4

2

3

5

Prim’s Algorithm

4

2

5

3

1

6

2

S3 = {1, 2, 3}

S4 = {1, 2, 3, 4}

1

4

2

3

5

Prim’s Algorithm

4

2

5

3

1

6

2

S4 = {1, 2, 3, 4}

S5 = {1, 2, 3, 4, 5}

Directed Spanning Tree (DST)
• Input
• A network (directed graph) G = (N,A)
• Arc cost cij for each edge arc (i,j)  A
• A designated root node s  N
• Optimization Problem
• Find a minimum-cost directed-out tree T = (N, A*) rooted at node s.
• Directed-Out Tree: T = (N, A*) contains a unique, directed path from s to every other node in N (every other node in the tree has in-degree = 1).
Is DST a (Pure) Network Flow Problem?
• Suggestion:
• Let b(s) = |N| - 1
• Let b(i) = -1 for i in N\{s}
• Let ij = 0
• Let uij = |N|
• Each node gets 1 unit of flow
• Total cost of flow is minimized
• Arcs carrying flow form a directed spanning tree

1

3

2

5

4

DST Example

10

10

1

s

5

5