Minimum Spanning Trees (CLRS 23)

Similar documents
Lecture 20: Minimum Spanning Trees (CLRS 23)

Minimum Spanning Trees (CLRS 23)

Spanning Trees. BFS, DFS spanning tree Minimum spanning tree. March 28, 2018 Cinda Heeren / Geoffrey Tien 1

Weighted Graphs. Weighted graphs may be either directed or undirected.

(Minimum) Spanning Trees

Lecture II: Minimium Spanning Tree Algorithms

Improving Union. Implementation. Union-by-size Code. Union-by-Size Find Analysis. Path Compression! Improving Find find(e)

CMPS 2200 Fall Graphs. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

Depth First Search. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong

4.1 Interval Scheduling. Chapter 4. Greedy Algorithms. Interval Scheduling: Greedy Algorithms. Interval Scheduling. Interval scheduling.

5/1/2018. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees

The University of Sydney MATH 2009

2 Trees and Their Applications

23 Minimum Spanning Trees

CMSC 451: Lecture 4 Bridges and 2-Edge Connectivity Thursday, Sep 7, 2017

Strongly connected components. Finding strongly-connected components

23 Minimum Spanning Trees

CSE 332. Data Structures and Parallelism

CSE 332. Graphs 1: What is a Graph? DFS and BFS. Data Abstractions. CSE 332: Data Abstractions. A Graph is a Thingy... 2

In which direction do compass needles always align? Why?

Theorem 1. An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices.

Graph Search (6A) Young Won Lim 5/18/18

Divided. diamonds. Mimic the look of facets in a bracelet that s deceptively deep RIGHT-ANGLE WEAVE. designed by Peggy Brinkman Matteliano

COMP 250. Lecture 29. graph traversal. Nov. 15/16, 2017

Applications of trees

Having a glimpse of some of the possibilities for solutions of linear systems, we move to methods of finding these solutions. The basic idea we shall

The R-Tree. Yufei Tao. ITEE University of Queensland. INFS4205/7205, Uni of Queensland

Single Source Shortest Paths (with Positive Weights)

learning objectives learn what graphs are in mathematical terms learn how to represent graphs in computers learn about typical graph algorithms

CSE 332. Graphs 1: What is a Graph? DFS and BFS. Data Abstractions. CSE 332: Data Abstractions. A Graph is a Thingy... 2

An undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V

Minimum Spanning Trees

Graph Search Algorithms

Planar convex hulls (I)

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

Graphs Depth First Search

Exam 2 Solutions. Jonathan Turner 4/2/2012. CS 542 Advanced Data Structures and Algorithms

SAMPLE CSc 340 EXAM QUESTIONS WITH SOLUTIONS: part 2

MAT3707. Tutorial letter 201/1/2017 DISCRETE MATHEMATICS: COMBINATORICS. Semester 1. Department of Mathematical Sciences MAT3707/201/1/2017

Outline. Computer Science 331. Computation of Min-Cost Spanning Trees. Costs of Spanning Trees in Weighted Graphs

, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management

CS 103 BFS Alorithm. Mark Redekopp

An Introduction to Clique Minimal Separator Decomposition

Grade 7/8 Math Circles March 4/5, Graph Theory I- Solutions

Closed Monochromatic Bishops Tours

Cycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!

CSC Design and Analysis of Algorithms. Example: Change-Making Problem

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

CS 461, Lecture 17. Today s Outline. Example Run

The Constrained Longest Common Subsequence Problem. Rotem.R and Rotem.H

17 Basic Graph Properties

Platform Controls. 1-1 Joystick Controllers. Boom Up/Down Controller Adjustments

18 Basic Graph Properties

MATERIAL SEE BOM ANGLES = 2 FINISH N/A

Shortest Paths in Graphs. Paths in graphs. Shortest paths CS 445. Alon Efrat Slides courtesy of Erik Demaine and Carola Wenk

d e c b a d c b a d e c b a a c a d c c e b

16.unified Introduction to Computers and Programming. SOLUTIONS to Examination 4/30/04 9:05am - 10:00am

Minimum Spanning Trees

On Hamiltonian Tetrahedralizations Of Convex Polyhedra

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

CSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp

Problem solving by search

Math 166 Week in Review 2 Sections 1.1b, 1.2, 1.3, & 1.4

A Gentle Introduction to Matroid Algorithmics

Priority Search Trees - Part I

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

DOCUMENT STATUS: RELEASE

b.) v d =? Example 2 l = 50 m, D = 1.0 mm, E = 6 V, " = 1.72 #10 $8 % & m, and r = 0.5 % a.) R =? c.) V ab =? a.) R eq =?

OpenMx Matrices and Operators

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

Preview. Graph. Graph. Graph. Graph Representation. Graph Representation 12/3/2018. Graph Graph Representation Graph Search Algorithms

Graphs. Graphs. Graphs: Basic Terminology. Directed Graphs. Dr Papalaskari 1

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

Data-Parallel Primitives for Spatial Operations Using PM. Quadtrees* primitives that are used to construct the data. concluding remarks.

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

kd-trees Idea: Each level of the tree compares against 1 dimension. Let s us have only two children at each node (instead of 2 d )

Phylogenetic Tree Inferences Using Quartet Splits. Kevin Michael Hathcock. Bachelor of Science Lenoir-Rhyne University 2010

Maximum Matching Width: new characterizations and a fast algorithm for dominating set

b. How many ternary words of length 23 with eight 0 s, nine 1 s and six 2 s?

Stronger Virtual Connections in Hex

MINI POST SERIES BALUSTRADE SYSTEM INSTALLATION GUIDE PRODUCT CODE: MPS-RP

1 Introduction to Modulo 7 Arithmetic

COMP108 Algorithmic Foundations

Copyright 2000, Kevin Wayne 1

Solutions for HW11. Exercise 34. (a) Use the recurrence relation t(g) = t(g e) + t(g/e) to count the number of spanning trees of v 1

(2) If we multiplied a row of B by λ, then the value is also multiplied by λ(here lambda could be 0). namely

Graphs Breadth First Search

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

5/7/13. Part 10. Graphs. Theorem Theorem Graphs Describing Precedence. Outline. Theorem 10-1: The Handshaking Theorem

Constructive Geometric Constraint Solving

CS 241 Analysis of Algorithms

Planar Upward Drawings

L.3922 M.C. L.3922 M.C. L.2996 M.C. L.3909 M.C. L.5632 M.C. L M.C. L.5632 M.C. L M.C. DRIVE STAR NORTH STAR NORTH NORTH DRIVE

DOCUMENT STATUS: LA-S5302-XXXXS LA, SSS, TRICEPS EXTENSION VERY

Outline. Circuits. Euler paths/circuits 4/25/12. Part 10. Graphs. Euler s bridge problem (Bridges of Konigsberg Problem)

CSE 373: AVL trees. Warmup: Warmup. Interlude: Exploring the balance invariant. AVL Trees: Invariants. AVL tree invariants review

Graphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari

MATERIAL SEE BOM ANGLES = 2 > 2000 DATE MEDIUM FINISH

A ' / 1 6 " 5 ' / 4 " A4.2 48' - 0" 3 12' - 7" 13' - 11" 10' - 0" 9' - 0" 2' - 6" 1. 2: 12 INDICATES SHOW MELT TYP ABV ABV

Transcription:

Mnmum Spnnn Trs (CLRS 3) T prolm Rll t nton o spnnn tr: Gvn onnt, unrt rp G = (V, E), sust o s o G su tt ty onnt ll vrts n G n orm no yls s ll spnnn tr (ST) o G. Any unrt, onnt rp s spnnn tr. Atully, rp usully s mny spnnn trs. Quston: How woul you o out nn ST o vn rp G? Answr: Run BFS or DFS; t rsultn BFS- or DFS-tr r spnnn trs o G. T mnmum spnnn tr (MST) prolm s t ollown: Gvn onnt, unrt, wt rp G ( (u, v) s wt w(u, v)), n spnnn tr T o mnmum wt: w(t ) = (u,v) T w(u, v). In otr wors, o ll spnnn trs o G, w wnt on o mnmum totl wts. W us mnmum spnnn tr s sort or mnmum wt spnnn tr). Exmpl: Wt o MST s + + + + + + + = 3 Not: MST s not unqu:.. (, ) n xn wt (, ) T MST prolm s mny ppltons: For xmpl, tnk out onntn ts wt mnml mount o wr or ros (ts r vrts, wt o s r stns twn ty prs). Also, ntwork sn n nrl (tlpons, ltrl, TV l, ro ntworks).

MST lortms T two lssl lortms or omputn MST r Kruskl s n Prm s lortms. Ty ot v sm runnn tm omplxty, n ty r ot ry lortms, ut ty us omplmntry ppros: Kruskl s lortms: Strt wt T onsstn o ll vrts ut no s. Consr t s n G n nrsn orr o wt. A to T unlss on so woul rt yl. Ts orrspons to rown t tr rom orst o V sonnt vrts. A on t tm, jonn two trs n t orst totr. E jon rus t numr o onnt omponnts n t orst y on. Prm s lortm: Strt wt n mpyt T, n n rtrry vrtx v. Grow T on t tm: t stp, to T t s o mnmum wt tt s xtly on npont n T. Ts rows tr on t tm. T urrnt tr s lwys onnt ut only ovrs prt o t vrts. 3 Corrtnss T orrtnss o ot MST lortms ollows rom t ollown nrl torm: T ut torm: Lt S st o vrts n rp G = (V, E), n onsr ll s wt on npont n S n t otr on n V S. Lt = (u, v) n o mnmum wt mon ll s tt ross t ut. Tn tr xsts MST tt ontns. Proo: Lt T MST o G. I T ontns = (u, v), tn w r on. I T os not ontn = (u, v), tn: Bus T s tr, tr s unqu pt n T twn ny two nos n n prtulr twn u, v. Bus u s on on s o t ut n v s on t otr, ts pt must ontn t lst n (x, y) T rossn t ut. Wn n = (u, v) to T, ts pt n orm yl. I w rmov (x, y) rom T n nst, tn: T = T (x, y) + (u, v) s spnnn tr; n T must v sm wt s T sn w(u, v) w(x, y) Tus T s lso MST, n tus tr s MST ontnn T n. T prtton o V nto (S, V S) s rrr to s ut, n t s wt on on npont n S n t otr on n V S r ll s tt ross t ut.

T Cut Torm llows us to sr vry strt ry lortm or MST: T = Wl T V DO Fn ut S rsptn T Fn mnml rossn S T = T {} Bot Prm s n Kruskl s lortms ollow ts strt lortm n tr orrtnss ollows rom t ut torm y osn sutl ut: Prm s: T ut s (T, V T ), tt s, t urrnt tr on on s, n t rmnn vrts on t otr. At pont t lortm s t mnmum rossn t ut, w, y t ut torm, w know must prt o n MST. Kruskl s: Wn n (u, v) os ut tt s t vrts n t st o u on on s n t vrts n t st o v on t otr. E s t smllst tt rosss t ut n tus y t ut torm, w know must prt o n MST. PRIM s lortm GnrL IDEA: Strt wt spnnn tr ontnn rtrry vrtx r n no s Grow spnnn tr y rptly n mnml wt onntn vrtx n urrnt spnnn tr wt vrtx not n t tr Implmntton: To n mnml onnt to urrnt tr w mntn prorty quu on vrts not n t tr. T ky/prorty o vrtx v s t wt o mnml wt onntn v to t tr. (W mntn pontr rom jny lst o v to v n t prorty quu). For no v mntn vst(v) su tt (v, vst(v)) s t st onntn v to t urrnt tr. 3

PRIM(r) /* ntlz */ For vrtx u V, u r DO: Insrt(P Q, u, ) Insrt(P Q, r, 0), vst(r) = NULL /* mn loop */ WHILE P Q not mpty DO u = Dlt-mn(P Q) For (u, v) E DO IF v P Q n w(u, v) < ky(v): vst[v] = u Drs-Ky(P Q, v, w(u, v)) Output s (u, vst(u)) s prt o MST. On t xmpl rp, t ry lortm woul work s ollows (strtn t vrtx ): ) ) ) ) ) ) ) )

Prm s nlyss: V INSERT s Wl loop runs V tms w prorm V Dltmn s W prorm t most on Drs-Ky or o t E s I us p s pquu, nsrts, lt-mn n rs-ky run n O(l V ) = O(( V + E ) lo V ) = O( E lo V ) tm. 5 Kruskl s Alortm Gnrl : Strt wt orst onsstn o V trs, on onsstn o on vrtx Consr s E n nrsn orr o tr wt; n t onnts two trs, t os not rt yls. Exmpl: ) ) ) ) ) ) ) ) 5

To mplmnt Kruskl s, w n to strutur tt mntns t prtl trs n s l to support t ollown oprtons: () ntlz tr s onsstn o snl vrtx; () r two vrts n t sm tr?; n () jon two trs totr. Astrtn urtr, w n tnk o tr s st o vrts. W n t strutur to stor st o vrts so tt w r l to: () rt st onsstn o on vrtx; () trmn o two vrts r n t sm st; () jon two sts. Ts typ o strutur s rrr to s n unon-n t strutur n ts oprtons r rrr to s: Mk-st(v): Crt st onsstn o v Unon-st(u, v): Unt st ontnn u n st ontnn v Fn-st(u): Rturn unqu rprsnttv or st ontnn u W n r-wrt Kruskl s lortm to us unon-n t strutur s ollows: KRUSKAL T = FOR vrtx v V : Mk-St(v) Sort s o E n nrsn orr y wt FOR = (u, v) E n orr DO IF Fn-St(u) Fn-St(v) THEN T = T {} Unon-St(u, v) Kruskl s nlyss: W us O( E lo E ) = O( E lo V ) tm to sort s n w prorm V Mk-St, V Unon-st, n E Fn-St oprtons. W wll suss smpl soluton to t Unon-Fn prolm su tt Mk-St n Fn- St tk O() tm n Unon-St tks O(lo V ) tm mortz. Wt ts mplmntton Kruskl s lortm runs n tm O( E lo E + V lo V ) = O(( E + V ) lo E ) = O( E lo V ) lk Prm s lortm.

Unon-Fn Kruskl s MST lortm n xprss n trms o n unon-n t strutur. As t turns out ts s nrl-purpos strutur tt s otr ppltons. Gnrlly spkn t Unon-Fn prolm s t ollown: W wnt to prov t strutur to mntn st o lmnts unr t ollown oprtons: Mk-st(v): Crt st onsstn o v Unon-st(u, v): Unt st ontnn u n st ontnn v Fn-st(u): Rturn unqu rprsnttv or st ontnn u. Smpl soluton Prps t smplst tt oms to mn s to mntn lmnts n sm st s lnk lst wt lmnt vn pontr to t rst lmnt n t lst (unqu rprsnttv). Exmpl: Sts 3 5 Rprsntton 3 5 Mk-St(v): Mk lst wt on lmnt O() tm Fn-St(u): Follow pontr n rturn unqu rprsnttv O() tm Unon-St(u, v): Lnk rst lmnt n lst wt unqu rprsnttv Fn-St(u) tr lst lmnt n lst wt unqu rprsnttv Fn-st(v) O( V ) tm (s w v to upt ll unqu rprsnttv pontrs n lst ontnn u) Wt ts smpl soluton t V Unon-St oprtons n Kruskl s lortm my tk O( V ) tm.. Improv soluton: W n mprov t prormn o Unon-St wt vry smpl moton: Alwys lnk t smllr lst tr t lonr lst (upt t pontrs o t smllr lst) I you tnk: ts s smpl, you r rt! As w ll sow low, su utully smpl n ntutv rsults n n mortz oun o O(lo V ) pr Unon-St, mortz. Ts s lortm ln t ts st!

Wy s ts nt? On Unon oprton tks tm proportonl to numr o pontr ns t ns to o On Unon-St oprton n stll tk O( V ) tm (It s possl tt w jon lst o V/ vrts to lst o V/ vrts, w rqurs V/ pontr upts). Kruskl s lortm prorms V Unon oprtons n totl T trk s to tnk ovr ll t Unon oprtons prorm y Kruskl s lortm. Consr lmnt u: Atr pontr or u s upt, u lons to lst o sz t lst oul t sz o t lst t ws n or t unon Atr k pontr ns, u s n lst o sz t lst k Sn t sz o t lrst st s V, t pontr o u n n t most lo V tms. In otr wors, ovr t ours o ll t Unon oprtons, lmnt n v ts pontr n only O(l V ) tms. Ts mns tt O(V ) Unon oprtons wll tk O( V lo V ) tm ltotr n t worst s Nots: Wt mprovmnt, Kruskl s lortm runs n tm O( E lo E + V lo V ) = O(( E + V ) lo E ) = O( E lo V ) lk Prm s lortm. St-o-t-rt A Unon-Fn t strutur wt ttr ouns s possl; owvr vn wn usn n mprov UF strutur Kruskl s lortm stys t O( E lo V ) n ts runnn tm wll omnt y sortn. T st uppr oun or omputn MST s O( E α( E, V )) wr α() s t nvrs Akrmn unton; α() s vry slowly rown unton, n prt onstnt. MST n omput n xpt O(V + E) tm usn rnomz lortm t lortm ws rktrou wn rst prsnt y Trjn tl n 5. Computn MST n trmnst lnr tm (usn omprsons) s opn prolm.