Upcoming SlideShare
×

# lecture 16

756 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
756
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
24
0
Likes
0
Embeds 0
No embeds

No notes for slide

### lecture 16

1. 1. Lecture 12 Minimum Spanning Tree
2. 2. Motivating Example: Point to Multipoint Communication <ul><li>Single source, Multiple Destinations </li></ul><ul><li>Broadcast </li></ul><ul><ul><li>All nodes in the network are destinations </li></ul></ul><ul><li>Multicast </li></ul><ul><ul><li>Some nodes in the network are destinations </li></ul></ul><ul><li>Only one copy of the information travels along common edges </li></ul><ul><ul><ul><li>Message replication along forking points only. </li></ul></ul></ul>1 2
3. 3. Spanning Tree <ul><li>We consider undirected graphs here. </li></ul><ul><li>A tree is a connected graph without a cycle </li></ul><ul><li>A spanning tree is a tree which has all vertices of the graph </li></ul><ul><li>There may be multiple spanning trees </li></ul><ul><li>We need to choose the minimum weight tree for broadcast. </li></ul>
4. 4. Blue edge spanning tree is the minimum weight spanning tree 5 4 4 5
5. 5. Properties of a Tree <ul><li>A tree of V vertices has V-1 edges </li></ul><ul><li>There exists a unique path between any two vertices of a tree. </li></ul><ul><li>Adding any edge to a tree creates a unique cycle. Breaking any edge on this cycle restores a tree. </li></ul>
6. 6. Minimum Spanning Tree Construction <ul><li>We maintain a set of edges A, which is initially empty. </li></ul><ul><li>Edges are added to A one at a time such that finally A becomes a minimum spanning tree. </li></ul><ul><li>Edges are never removed from A. </li></ul><ul><li>So ``safe’’ edges must be added to A, i.e., at any stage A must be a part of a spanning tree. </li></ul>
7. 7. Safe Edge Addition <ul><li>Consider a cut in a graph (a cut consists of 2 sets which partition the vertex set). </li></ul><ul><li>A cut respects a set of edges I if no edge in the set crosses the cut. </li></ul><ul><li>A minimum weight edge crossing a cut is denoted a light weight edge in the cut </li></ul>{A,B,C} {D,E,F} constitute a cut. Let I = {edge AB, edge EF}.Cut {A,B,C}, {D,E,F} respects set I Edge CD is a light weight edge in the example cut. A B C D E F 2 1 3 1
8. 8. <ul><li>Let A be a subset of a MST (minimum weight spanning tree). </li></ul><ul><li>Let (S, V – S) be any cut that respects A </li></ul><ul><li>Let edge (u, v) be a light edge crossing the cut </li></ul><ul><li>Then A  (u, v) is subset of a MST </li></ul>
9. 9. Assume that all the edge weights are distinct. Let no MST containing A contain edge (u, v). Add the edge (u, v) to T Consider a MST T containing A Since (u, v) is not in T, T  (u, v) contains a cycle, and (u, v) is in the cycle. Edge (u, v) are in the opposite sides of the cut. Since any cycle must cross the cut even number of times, there exists at least one other edge (x, y) crossing the cut. Clearly, w(x, y) > w(u, v).
10. 10. The edge (x, y) is not in A because (x, y) crosses the cut, and the cut respects A. Removing (x, y) from the cycle, breaks the cycle and hence creates a spanning tree, T’, s.t. T’ = T  (u, v) – (x, y) w(T’) = w(T) + w(u, v) – w(x, y)  w(T) (as w(u, v) < w(x, y)) This contradicts the fact that T is a MST.
11. 11. <ul><li>So we always find a cut that respects A, </li></ul><ul><li>And add a light edge across the cut to A. </li></ul><ul><li>Kruskals and Prims algorithms find the cut differently. </li></ul>
12. 12. Kruskals Algorithm <ul><li>A =  </li></ul><ul><li>For each vertex u in V, Create_Set(u) </li></ul><ul><li>Sort E in increasing order by weight w </li></ul><ul><li>For each edge (u,v) in the sorted list </li></ul><ul><ul><li>If Set(u)  = Set(v) </li></ul></ul><ul><ul><ul><li>Add (u,v) to A </li></ul></ul></ul><ul><ul><ul><li>Union Set(u) and Set(v) </li></ul></ul></ul><ul><li>Return A; </li></ul>
13. 13. Complexity Analysis <ul><li>The operations create set, testing whether set(u) == set(v), union operations can be done in log V operations, using Union find data structure. </li></ul><ul><li>Step 1 can be done in Vlog V </li></ul><ul><li>Step 2 can be done in Elog E </li></ul><ul><li>Step 3 can be done in Elog V </li></ul><ul><li>Overall complexity is O(Vlog V + Elog E + Elog V) or O((V + E)log V) </li></ul>
14. 14. 5 1 0 2 2 8 5 7 5 1 0 2 2 8 5 7 5 1 0 2 2 8 5 7 5 1 0 2 2 8 5 7 5 1 0 2 2 8 5 7
15. 15. Prims Algorithm <ul><li>Maintains a set of vertices S already in the spanning tree. </li></ul><ul><li>Initially, S consists of one vertex r, selected arbitrarily. </li></ul><ul><li>For every vertex u in V – S, maintain the weight of the lightest edge between u and any vertex in S. </li></ul><ul><li>If there is no edge between u and S, then this weight associated with u is infinity. </li></ul>
16. 16. <ul><li>Add the vertex with the least weight to S. </li></ul><ul><li>This is in effect adding the light weight edge crossing the cut S and V-S. </li></ul><ul><li>Whenever a vertex is added to S, the weights of all its neighbors are reduced, if necessary. </li></ul>
17. 17. Pseudo-Code For each u in V, key[u] =  S =  Pred[r] = NULL Key[r] = 0 <ul><li>While V  = S </li></ul><ul><ul><li>u = Extract_Min(V-S) </li></ul></ul><ul><ul><li>For each (v in Adj(u)) </li></ul></ul><ul><ul><li>if (v not in S) key(v) = min(w(u, v), key(v)) </li></ul></ul><ul><ul><li>and pred(v) = u </li></ul></ul><ul><ul><li>Add u in S </li></ul></ul>
18. 18. For each v in Adj[u]…. can be done in E complexity Rest of the loop can be done in V 2 complexity So, overall O(V 2 ) Using heaps we can solve in O((V + E)logV)
19. 19. Example 0 s 7 5 7 2 1 8 5 3 2 5 3 1 s 0 2 8 5 7 2 8 5 s 0 7 3 1 5 2 3 5 8 0 3 2 5 s 7 2 1 8 5 5 3 1 8 5 s 0 7 2 3 1 5 2 3 5 1 3 8 5 s 0 7 2 1 5 2 3 5 1