© 2007 seth james nielson minimum spanning trees … or how to bring the world together on a budget
DESCRIPTION
© 2007 Seth James Nielson Carving Trees from Graphs BFS creates tree (or forest) BF-tree contains shortest paths DFS creates tree (or forest) BFS creates tree (or forest) BF-tree contains shortest paths DFS creates tree (or forest)TRANSCRIPT
![Page 1: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/1.jpg)
© 2007 Seth James Nielson
Minimum Spanning Trees
… or how to bring the world together on a budget
![Page 2: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/2.jpg)
© 2007 Seth James Nielson
Remembering Graphs
Relationships between entities
Weighted edges quantify relationships
![Page 3: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/3.jpg)
© 2007 Seth James Nielson
Carving Trees from Graphs
BFS creates tree (or forest)BF-tree contains shortest
pathsDFS creates tree (or forest)
![Page 4: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/4.jpg)
© 2007 Seth James Nielson
Spanning TreeDerived from connected
graphContains all verticesIs a tree (no cycles)Obviously, there could be
many
![Page 5: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/5.jpg)
© 2007 Seth James Nielson
The Math ViewG=(V,E) is a connected
graphT=(V,E) is a spanning tree
on G iffVT = VG, ET EGT contains no cycles
![Page 6: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/6.jpg)
© 2007 Seth James Nielson
RETURN OF THE SEARCH!
BF tree is a spanning treeDF tree is a spanning tree
![Page 7: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/7.jpg)
© 2007 Seth James Nielson
Philosophical ViewA tree on a graph is
filter on the set of relationships
enable discovery of new relationships
or meta-relationshipsFor example, BF and DF
trees
![Page 8: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/8.jpg)
© 2007 Seth James Nielson
Spanning Trees and Weights
Tree in weighted graph has an associated weight
Weight is just sum of weights of edges in the tree
![Page 9: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/9.jpg)
© 2007 Seth James Nielson
Minimum Spanning Tree
An MST on Gis a spanning treeweight <= every other ST on G
NOTE: any connected subgraph with min weight must be a treeRemoving a cyclic edge
Preserves connectednessReduces weight
![Page 10: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/10.jpg)
© 2007 Seth James Nielson
A “Cut” of GA cut partitions vertices (S,V-
S)Edge (u,v) crosses the cut if
u in Sv in V-S
A cut respects A E if none of the edges in A cross the cut
![Page 11: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/11.jpg)
© 2007 Seth James Nielson
“Light” EdgesA light edge satisfying a
propertyHas min weight for all edges
that satisfy the property
![Page 12: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/12.jpg)
© 2007 Seth James Nielson
Generic MST Algorithm
(setup)Let A be a subset of EA is a subset of some MST(u,v) is a safe edge for A iff
A U {(u,v)} MST
![Page 13: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/13.jpg)
© 2007 Seth James Nielson
Generic-MST(G, w)1. A <- 02. while A is not a spanning tree3. do find edge (u,v) that is safe
for A4. A <- A U {(u,v)}5. return A
![Page 14: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/14.jpg)
© 2007 Seth James Nielson
Generic MST Loop Invariant
Initialization: Line 1Trivially satisfies
Maintenance:Lines 2-4Only add safe edges
Termination:All edges are in MSTTherefore, A (line 5) must be an
MST
![Page 15: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/15.jpg)
© 2007 Seth James Nielson
Theorem 1(recognizing safe
edges)LetG=(V,E) is connected, undirected, and weighted
Let A be a subset of E (in some MST)
Let (S,V-S) be a cut of G that respects A
Let (u,v) be a light edge crossing (S, V-S)
(u,v) is safe for A
![Page 16: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/16.jpg)
© 2007 Seth James Nielson
Proof of Theorem 1See CLRS 23.1 (p 563-565)
![Page 17: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/17.jpg)
© 2007 Seth James Nielson
Generic UselessnessOf course, the generic
algorithm isn’t very usefulThe hard part if finding a
safe edge.Two greedy algorithms
Kruskal’s algorithmPrim’s algorithm
![Page 18: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/18.jpg)
© 2007 Seth James Nielson
MST-Kruskal(G,W)1. A = {}2. for each v in V3. MAKE-SET(v)4. sort E in nondecreasing order by
weight5. for (u,v) in sorted-E6. if FIND-SET(u) != FIND-SET(v)7. A = A + {(u,v)}8. UNION(u,v)9. return A
![Page 19: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/19.jpg)
© 2007 Seth James Nielson
Kruskal: IntuitionCreate disjoint sets for each
vIn the loop
Find light edge (using sort)The disjoint sets represent the
cut (partition)The cut (A,V-A) respects A(u,v) is light edge crossing cut(u,v) is safe for A
![Page 20: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/20.jpg)
© 2007 Seth James Nielson
Kruskal’s Running Time
MAKE-SET takes O(v) timeSorting edges takes O(E log
E)Find set for each e O(E a(V))Union is O(1)Total time is O(E log E)(or O(E log V) )
![Page 21: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/21.jpg)
© 2007 Seth James Nielson
Prim’s AlgorithmStarts with arbitrary rootIn loop
Adds a light edge (u,v)u in the treev out of the tree
Uses a min priority queue for vMST-PRIM(G,W,r) on next
slide
![Page 22: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/22.jpg)
© 2007 Seth James Nielson
1. for each u in V2. key[u] = INFINITY3. p[u] = NULL4. key[r] = 05. Q = CREATE-MIN-QUEUE(V)6. while Q != {}7. u = EXTRACT-MIN(Q)8. for each v adjacent to u9. if v is in Q and w(u,v) < key[v]10. p[v] = u11. key[v] = w(u,v)12. A = { (v,p[v]): v is in V - {r}}13. return A
![Page 23: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/23.jpg)
© 2007 Seth James Nielson
Prim’s Running TimeIf we use a binary heap
O(E lg V)Fibonacci heap
O(E + V lg V)
![Page 24: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/24.jpg)
© 2007 Seth James Nielson
ApplicationsThe phone networkApproximation to Traveling
Salesman
![Page 25: © 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget](https://reader036.vdocuments.us/reader036/viewer/2022062906/5a4d1b567f8b9ab0599a95ba/html5/thumbnails/25.jpg)
© 2007 Seth James Nielson