25
22/6/16 2004 SDU Lecture 7- Minimum Spanning Tree--Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck Spanning Tree Problem 4.Other MST algorithms

2015-10-20 2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

Embed Size (px)

Citation preview

Page 1: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

23/4/20 2004 SDU

Lecture 7-Minimum Spanning

Tree--Extension

1. Properties of Minimum Spanning Tree

2. Secondary Minimum Spanning Tree

3. Bottleneck Spanning Tree Problem

4. Other MST algorithms

Page 2: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 2

Properties of MST

Property 1: Let (u, v) be a minimum-weight edge in a graph G = (V, E), then (u, v)

belongs to some minimum spanning tree of G.

Proof: Let A be the empty set of edges. Then A is a subset of some minimum spanning tree, and A does not include (u, v). Then cut (u, V\u) respects A. Edge (u, v) is a light edge crossing cut (u, V\u). According to theorem 23.1, (u, v) is a safe edge for A. Hence, (u, v) belongs to some minimum spanning tree.

Another method: Suppose T is an arbitrary MST, and (u, v) is not in T. Then T + (u, v) contains a cycle. Let f be any edge other than e on the cycle, then T + (u, v) - f is another MST and it contains (u, v).

Page 3: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 3

Properties of MST

Property 2 Let T be a minimum spanning tree of a graph G, and let L be the

sorted list of the edge weights of T, then for any other minimum spanning tree T’ of G, the list L is also the sorted list of edge weights of T’.– A corollary of Property 3.– If all the edge weights are distinct, then MST is unique.

Property 3 Let T be a minimum spanning tree of a graph G, and let T’ be an

arbitrary spanning tree of G, suppose the edges of each tree are sorted in non-decreasing weight order, that is, w(e1)w(e2) … w(en-1) and w(e1’)w(e2’) … w(en-1’), then for 1 i n-1, w(ei) w(ei’).

Page 4: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 4

Proof of Property 3

(Prove by contradiction) Suppose without loss of generality that there exists an index i1 such that w(e1) w(e1’), w(e2) w(e2’), …, w(ei-1) w(ei-1’), but w(ei) >w(ei’). This indicates that w(en-1) w(en-2) … w(ei)>w(ei’) w(ei-1’) … w(e1’). So, if we add any ex’{ e1’, e2’, …, ei’} onto T, then either ex’ is an edge of {e1, e2,…, ei-1}, or a cycle is

formed which includes only edges from {ex’, e1, e2,…, ei-1}. Thus if we add all the edges { e1’, e2’, …, ei’} onto T and delete {ei, …, en-1}, the connected components of { e1’, e2’, …, ei’, e1, e2, …, ei-1} are just the same as those of {e1, e2, .., ei-1}. Thus {e1’, e2’, …, ei’ e1, e2, .., ei-

1} have the same number of connected components as {e1, e2, .., ei-1} have, i.e., n-i+1. A contradiction, since {e1’, e2’, …, ei’} are tree edges, they can have at most n-i connected components.

Page 5: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 5

edges in {e1, …, ei-1} edges in {e1’, …, ei’}

{e1’, …, ei’} are all included in the components of Gi-1,So, red edges cannot have less components.

Page 6: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 6

Second-best MST

Let G = (V, E) be an undirected, connected graph with weight function w: E R, and suppose that | E | | V | and all edge weights are distinct, a second-best minimum spanning tree is a spanning tree T such that w(T) = minT’’-{T’}{w(T’’)}, where is the set of all spanning trees of G, and T’ is a minimum spanning tree of G.

Page 7: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 7

MST Property

Let G = (V, E) be an undirected, connected graph with weight function w: E R, and suppose that | E | | V | and all edge weights are distinct. Then the minimum spanning tree of G is unique. According to Property 2.

Page 8: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 8

Second-best MST Properties

The second-best minimum spanning tree may not be unique.

1

2

4

5

3

1

2

4

1 43 1

2

5

MST

Page 9: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 9

Second-best MST Properties

A second-best minimum spanning tree can be obtained from the minimum spanning tree by replacing a single edge from the tree with another edge not in the tree. By contradiction. Suppose T1 is the MST and T2 is a

second-best MST, and they differ by at least two edges, we will get another spanning tree T3 which is not equal to T1 but better than T2, thus contradicts that T2 is second-best.

Page 10: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 10

Suppose e1is the minimum edge in T1\ T2. Then T2 {e1} contains a cycle on which there

must be some edge f which belongs to T2 but not belongs to T1, since otherwise T1 would have a cycle.

Let T3=T2 {e1} \f. Then T3 is a spanning tree.

We claim that

1.T3 is better than T2.2.T3 is not equal to T1.Thus, contradicts to that T2 is a second-best

MST.

Page 11: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 11

Proof of 1: We claim that w(f) > w(e1).  Proof by contradiction:  Assume that w(f) < w(e1).  If we add f to T1, we get a cycle C, which contains some edge e' in T1 but e' is  not in T2 (otherwise, T2 would contain a cycle). Therefore, the set of edges T4 = T1 - {e'} {f} form a spanning tree, and we must have w(e') < w(f), since otherwise T4 would be a spanning tree with weight less than w(T1 ). Thus, w(e') < w(f) < w(e1),  which contradicts our choice of e1 as the  edge in T1 - T2 of minimum weight. Since T3=T2 {e1} \f, T3 is better than T2.

Proof of 2: T3 differs from T2 by only one edge, while T1 differs from T2 by at least two edges, so, T3 is not equal to T1.

Thus, we have formed a spanning tree T3 whose weight is less than w(T2) but is not T1. Hence, contradicts that T2 is a second-best minimum spanning tree.

Another Method: Let e1 be the edge with minimum weight in T2 \ T1.We aim to find an edge f in T1 \ T2, add f into T2, and delete another edge g in the cycle just formed such that f < g.Note: e1 T1 contains a cycle, in which there must be an edge f T1 \ T2 and f < e1. Then f T2 contains a cycle in which there must be an edge g T2 \ T1. Then f < e1 g. Then T3 = T2 f \ g is better than T2 and is distinct with T1.

Page 12: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 12

Compute the Second-best MST

Idea: use the property in previous page: (u, v): An edge of MST T, (x, y): an edge in G but not

in T w (T’) = w (T) + (w (x, y) – w (u, v))

Let T be a spanning tree of G and for any two vertices u, v V, let max [u, v] be the maximum weight among all edges on the unique path between u and v in T.

How to compute max [u, v]?

Page 13: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 13

Compute_max(T)1. for each pair of vertices u, v V2. do max[u, v] 03. for each vertex s V4. do BFS (T, s)

BFS(T, s)1. for each vertex u V2. do color[u] WHITE3. color[s] GRAY4. Q 5. ENQUEUE(Q, s)6. while Q 7. do u DEQUEUE(Q)8. for each v Adj[u]9. do if color[v] = WHITE10. then color[v] GRAY11. max[s, v] max{w(u, v), max[s, u]}12. ENQUEUE(Q, v)13. color[u] BLACK

//(V2)

Page 14: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 14

Compute the Second-best MST

Second-Best-MST(G)1. Compute a MST T for G2. Compute max[u, v] for each pair of vertices in T3. For each edge (u, v) in G but not T, compute the

difference w(u, v) – max[u, v]4. Find the smallest positive difference and replace

the max_edge[u, v] with corresponding edge (u, v).

Note: max_edge[u, v] means the edge with maximum weight in the path connecting u and v in T. It can be easily computed.

Page 15: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 15

Time Complexity Analysis

Compute-max(T): (V2)

Second-Best-MST(G): (V2) by using Fibonacci Heap.

Page 16: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 16

Bottleneck Spanning Tree

A bottleneck spanning tree T of a connected, weighted and undirected graph G is a spanning tree of G whose largest edge weight is minimum over all spanning trees of G. Let T1, T2, …, Tm are all the spanning trees G, and the

largest edge of each tree is et1, et2, …, etm. If w(eti) w(etj) for 1 j m and j i, then Ti is a bottleneck spanning tree.

The value of a BST T is the maximum edge weight among all the edges in T.

The bottleneck spanning tree may not be unique.

Page 17: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 17

BST vs. MST

Every minimum spanning tree is a bottleneck spanning tree. Property 3 implies it. Another proof: Let T be a MST and T’ be a BST, let the maximum-weight

edge in T and T’ be e and e’, respectively. Suppose for the contrary that the MST T is not a BST, then we have w(e)>w(e’), which also indicates that the weight of e is greater than that of any edges in T’. Removing e from T disconnects T into two subtrees T1 and T2, suppose the two end vertices of e are x and y, in T1 and T2 respectively. Then there must exist a path in T’ that connects x and y. Then there must be an edge f=(u, v) on this path such that u T1 and v T2 . Thus T1T2 {f} forms a new tree T’’ with w(T’’) = w(T) - w(e) + w(f) < w(T), a contradiction to the fact that T is MST, thus, an MST is also a BST.

Page 18: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 18

The BST Problem

The Problem: Input: A weighted, connected and undirected graph G. Output: A BST T of G.

A solution: Kruskal’s and Prim’s Algorithm works for the BST

problem.

More efficient algorithm exist for the problem?

Page 19: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 19

A Verification Problem

A verification problem: Input: A graph G = (V, E; W) and b Output: TRUE if the value of the bottleneck spanning

tree of G is at most b and FALSE otherwise

How to solve this problem in linear time?

an integer

Page 20: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 20

CHECKBOTTLENECK(G, b)1. for each vertex u V[G]2. do color[u] WHITE3. u randomly chosen vertex in G4. DFS(u, b) //O(V+E)5. for each vertex u V[G]6. do if color[u] = WHITE7. then return FALSE8. return TRUE

DFS(u, b)

1. color[u] GRAY

2. for each v Adj[u]

3. do if color[v] = WHITE and w(u, v)b

4. then DFS(v, b)

5. color[u] BLACK

Page 21: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 21

Solve the BST Problem

BOTTLENECK(G)

1. sort the weights of edges of G in non-decreasing order: w[1], w[2], …, w[| E |]

2. start 1

3. end | E |

4. while start < end

5. do middle (start + end)/26. if CHECKBOTTLENECK(G, w[middle]) = FALSE

7. then start middle+1

8. else end middle //in the end there is a BST with value =w[start],

9. u randomly chosen a vertex of G

10. call DFS(u, w[start]) to build a spanning tree

Page 22: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 22

Solve the Problem in Linear Time

Can the problem be solved in linear time?

Time complexity:Sorting: O(E lgV)Finding the value of BST: O((V+E) lgE)=O(E lgV)Total: O(E lgV)

Page 23: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 23

MAYBE-MST-A

1. sort the edges into non-increasing order of edge weights w2. TE3. for each edge e, taken in non-increasing order by weight4. do if T-{e} is a connected graph5. then TT-e6. return T

• Does this algorithm correctly output a MST?Yes. According to exercise 23.1-5, each time we delete anedge that is of maximum-weight in a cycle, in the last, T contains a MST, and since T itself does not contain cycles,T itself is a MST.

• Time complexity? O(E2). If e=(u, v), call DFS(T, u), if v is found, return True; return False.

Page 24: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 24

MAYBE-MST-B

1. T2. for each edge e, taken in arbitrary order3. do if T {e} has no cycles4. then TT {e} 5. return T

Correct? No. Example: Algorithm will return 22if 221 is the edge order.

Time complexity? O(E+VlgV) using weighted lists.

2

2

1

Page 25: 2015-10-20  2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck

2004 SDU 25

MAYBE-MST-C

1. T2. for each edge e, taken in arbitrary order3. do TT {e} 4. if T has a cycle C5. then let e’ be the maximum-weight edge on C6. TT-{e’}7. return T

•Correct? Yes. T=G-{e’| e’ is deleted in the process}. Since each deleted edge e’ is the edge of maximum weight ona cycle, so, after deleting these edges, T still contains a MST accordingto exercise 23.1-5. And since T does not contain cycles, T itself is a MST.•Time complexity? O(VE).