Chapter 18. Minimum Spanning Trees Minimum Spanning Trees. a d. a d. a d. f c

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

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

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

Exam 1 Solution. CS 542 Advanced Data Structures and Algorithms 2/14/2013

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

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

Graph Contraction and Connectivity

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

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

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

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

CS 241 Analysis of Algorithms

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

COMP108 Algorithmic Foundations

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

Module graph.py. 1 Introduction. 2 Graph basics. 3 Module graph.py. 3.1 Objects. CS 231 Naomi Nishimura

Graph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2

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

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

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

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

CS200: Graphs. Graphs. Directed Graphs. Graphs/Networks Around Us. What can this represent? Sometimes we want to represent directionality:

0.1. Exercise 1: the distances between four points in a graph

CS61B Lecture #33. Administrivia: Autograder will run this evening. Today s Readings: Graph Structures: DSIJ, Chapter 12

1 Introduction to Modulo 7 Arithmetic

The University of Sydney MATH2969/2069. Graph Theory Tutorial 5 (Week 12) Solutions 2008

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

Greedy Algorithms, Activity Selection, Minimum Spanning Trees Scribes: Logan Short (2015), Virginia Date: May 18, 2016

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

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

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

Planar Upward Drawings

Weighted graphs -- reminder. Data Structures LECTURE 15. Shortest paths algorithms. Example: weighted graph. Two basic properties of shortest paths

Why the Junction Tree Algorithm? The Junction Tree Algorithm. Clique Potential Representation. Overview. Chris Williams 1.

Garnir Polynomial and their Properties

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

Constructive Geometric Constraint Solving

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

Present state Next state Q + M N

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

Algorithmic and NP-Completeness Aspects of a Total Lict Domination Number of a Graph

12. Traffic engineering

Announcements. Not graphs. These are Graphs. Applications of Graphs. Graph Definitions. Graphs & Graph Algorithms. A6 released today: Risk

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

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

# 1 ' 10 ' 100. Decimal point = 4 hundred. = 6 tens (or sixty) = 5 ones (or five) = 2 tenths. = 7 hundredths.

1. Determine whether or not the following binary relations are equivalence relations. Be sure to justify your answers.

GREEDY TECHNIQUE. Greedy method vs. Dynamic programming method:

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

Problem solving by search

Section 10.4 Connectivity (up to paths and isomorphism, not including)

EE1000 Project 4 Digital Volt Meter

Numbering Boundary Nodes

Seven-Segment Display Driver

Minimum Spanning Trees

NP-Completeness. CS3230 (Algorithm) Traveling Salesperson Problem. What s the Big Deal? Given a Problem. What s the Big Deal? What s the Big Deal?

Designing A Concrete Arch Bridge

Trees as operads. Lecture A formalism of trees

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

Nefertiti. Echoes of. Regal components evoke visions of the past MULTIPLE STITCHES. designed by Helena Tang-Lim

Using the Printable Sticker Function. Using the Edit Screen. Computer. Tablet. ScanNCutCanvas

Page 1. Question 19.1b Electric Charge II Question 19.2a Conductors I. ConcepTest Clicker Questions Chapter 19. Physics, 4 th Edition James S.

QUESTIONS BEGIN HERE!

S i m p l i f y i n g A l g e b r a SIMPLIFYING ALGEBRA.

A Simple Code Generator. Code generation Algorithm. Register and Address Descriptors. Example 3/31/2008. Code Generation

Announcements. These are Graphs. This is not a Graph. Graph Definitions. Applications of Graphs. Graphs & Graph Algorithms

Lecture 20: Minimum Spanning Trees (CLRS 23)

Register Allocation. Register Allocation. Principle Phases. Principle Phases. Example: Build. Spills 11/14/2012

Solutions to Homework 5

QUESTIONS BEGIN HERE!

CS September 2018

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

Chapter 9. Graphs. 9.1 Graphs

N=4 L=4. Our first non-linear data structure! A graph G consists of two sets G = {V, E} A set of V vertices, or nodes f

A 4-state solution to the Firing Squad Synchronization Problem based on hybrid rule 60 and 102 cellular automata

CSI35 Chapter 11 Review

XML and Databases. Outline. Recall: Top-Down Evaluation of Simple Paths. Recall: Top-Down Evaluation of Simple Paths. Sebastian Maneth NICTA and UNSW

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

FSA. CmSc 365 Theory of Computation. Finite State Automata and Regular Expressions (Chapter 2, Section 2.3) ALPHABET operations: U, concatenation, *

Integration Continued. Integration by Parts Solving Definite Integrals: Area Under a Curve Improper Integrals

Outline. Binary Tree

CSE303 - Introduction to the Theory of Computing Sample Solutions for Exercises on Finite Automata

Jonathan Turner Exam 2-10/28/03

RAM Model. I/O Model. Real Machine Example: Nehalem : Algorithms in the Real World 4/9/13

Multipoint Alternate Marking method for passive and hybrid performance monitoring

Construction 11: Book I, Proposition 42

(Minimum) Spanning Trees

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

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

DUET WITH DIAMONDS COLOR SHIFTING BRACELET By Leslie Rogalski

Register Allocation. How to assign variables to finitely many registers? What to do when it can t be done? How to do so efficiently?

Self-Adjusting Top Trees

This chapter covers special properties of planar graphs.

(a) v 1. v a. v i. v s. (b)

10/30/12. Today. CS/ENGRD 2110 Object- Oriented Programming and Data Structures Fall 2012 Doug James. DFS algorithm. Reachability Algorithms

Organization. Dominators. Control-flow graphs 8/30/2010. Dominators, control-dependence. Dominator relation of CFGs

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

The University of Sydney MATH 2009

Module 2 Motion Instructions

Transcription:

Chptr 8 Minimum Spnning Trs In this hptr w ovr importnt grph prolm, Minimum Spnning Trs (MST). Th MST o n unirt, wight grph is tr tht spns th grph whil minimizing th totl wight o th gs in th tr. W irst in spnning tr n minimum spnning trs prisly n thn prsnt two squntil lgorithm n on prlll lgorithm, whih r rsptivly Kruskl s, Prim s, n Borůvk s. All o ths lgorithms utiliz n importnt ut proprty, whih w lso sri. 8. Minimum Spnning Trs Rll tht w sy tht n unirt grph is orst i it hs no yls n tr i it is lso onnt. Givn onnt, unirt grph, w might wnt to intiy sust o th gs tht orm tr, whil touhing ll th vrtis. W ll suh tr spnning tr. Dinition 8.. For onnt unirt grph G = (V, E), spnning tr is tr T = (V, E ) with E E. Not tht grph n hv mny spnning trs, ut ll hv V vrtis n V gs. Exmpl 8.2. A grph on th lt, n two possil spnning trs. 35

3 CHAPTER 8. MINIMUM SPANNING TREES Qustion 8.3. Dsign n lgorithm or ining spnning tr o onnt, unirt grph? On wy to gnrt spnning tr is simply to o grph srh. For xmpl th DFStr o DFS is spnnig tr, s it ins pth rom sour to ll th vrtis. Similrly, w n onstrut spnning tr s on BFS, y ing h g tht ls to th isovry o n unvisit vrtx to th tr. DFS n BFS r work-iint lgorithms or omputing spnning trs ut s w isuss thy r not goo prlll lgorithms. Qustion 8.4. Cn you think o n lgorithm with polylogrithmi spn or ining spnning tr o onnt unirt grph? Anothr wy to gnrt spnning tr is to us grph ontrtion, whih s w hv sn n on in prlll. Th i is to us str ontrtion n ll th gs tht r slt to in th strs throughout th lgorithm to th spnning tr. Rll tht grph hs mny spnning trs. In wight grphs, w my intrst in ining th spnning tr with th smllst totl wight (i.. sum o th wights o its gs). Dinition 8.5. Givn onnt, unirt wight grph G = (V, E, w), th minimum (wight) spnning tr (MST) prolm rquirs ining spnning tr o minimum wight, whr th wight o tr T is in s: w(t ) = w(). E(T ) Exmpl 8.. A grph (lt) n its MST (right). 7 2 5 3 4 2 3 4

8.2. ALGORITHMS FOR MINIMUM SPANNING TREES 37 Exmpl 8.7. Minimum spnning trs hv mny intrsting pplitions. On xmpl onrns th sign o ntwork. Suppos tht you r wiring uiling so tht ll th rooms r onnt vi iirtionl ommunition wirs. Suppos tht you n onnt ny two rooms t th ost o th wir onnting th rooms, whih pns on th spiis o th uiling n th rooms ut is lwys positiv rl numr. W n rprsnt th possil onntion twn rooms s grph, whr vrtis rprsnt rooms n wight gs rprsnt possil onntions long with thir ost (wight). To minimiz th ost o th wiring, you oul in minimum spnning tr o th grph. 8.2 Algorithms or Minimum Spnning Trs Thr r svrl lgorithms or omputing minimum spnning trs. Thy ll, howvr, r s on th sm unrlying proprty out uts in grph, whih w will rr to s th light-g proprty. Intuitivly, th light-g proprty (prisly in low) stts tht i you prtition th grph into two, th minimum g twn th two prts hs to in th MST. Th light-g proprty givs wy to intiy lgorithmilly th gs o n MST. In our isussion w will ssum tht ll gs hv istint wights. This ssumption uss no loss-o-gnrlity, us light-g proprty llows us to rk tis ritrrily, whih w n tk vntg o y or xmpl rking tis s on som ritrry orring o gs suh s thir position in th input. Qustion 8.8. Consir grph whr h g hs istint wight, how mny MST s n th grph hv? A simpliying onsqun o this ssumption is tht th MST o grph with istint g wigths uniqu. Dinition 8.9. For grph G = (V, E), ut is in in trms o non-mpty propr sust U V. This st U prtitions th grph into (U, V \ U), n w rr to th gs twn th two prts s th ut gs writtn E(U, U), whr U = V \ U. Th sust U us in th inition o ut might inlu singl vrtx v, in whih s th ut gs woul ll gs inint on v. But th sust U must propr sust o V (i.., U V ). W somtims sy tht ut g rosss th ut.

38 CHAPTER 8. MINIMUM SPANNING TREES Lmm 8. (Light-Eg Proprty). Lt G = (V, E, w) onnt unirt wight grph with istint g wights. For ny ut o G, th minimum wight g tht rosss th ut is in th minimum spnning tr MST(G) o G. U u v V\U Proo. Th proo is y ontrition. Assum th minimum-wight g = (u, v) is not in th MST. Sin th MST spns th grph, thr must som simpl pth P onnting u n v in th MST (i.., onsisting o just gs in th MST). Th pth must ross th ut twn U n V \ U t lst on sin u n v r on opposit sis. Lt n g in P tht rosss th ut. By ssumption th wight o is lrgr thn tht o. Now, insrt into th grph this givs us yl tht inlus oth n n rmov rom th grph to rk th only yl n otin spnning tr gin. Now, sin th wight o is lss thn tht o, th rsulting spnning tr hs smllr wight. This is ontrition n thus must hv n in th tr. Exmpl 8.0. Two xmpl uts. For h ut, w n in th lightst g tht rosss tht ut, whih r th gs with wight 2 (lt) n 4 (right) rsptivly. 7 5 2 3 4 7 5 2 3 4 W now stt n prov th light-g proprty (Lmm 8.). An importnt implition o Lmm 8. is tht ny minimum-wight g tht rosss ut n immitly to th MST. In t, ll o th thr lgorithms tht w will onsir in this hptr tk vntg o this implition. For xmpl, Kruskl s lgorithm onstruts th MST y grily ing th ovrll minimum g. Prim s lgorithm grows n MST inrmntlly y onsiring ut twn th urrnt MST n th rst o grph. Borůvk s lgorithm onstruts tr in prlll y onsiring th ut in y h n

8.2. ALGORITHMS FOR MINIMUM SPANNING TREES 39 vry vrtx. In th nxt stion, w rily rviw Kruskl s n Prim s lgorithm n spn most o our tim on prlll vrint o Borůvk s lgorithm. Rmrk 8.2. Evn though Borůvk s lgorithm is th only prlll lgorithm, it ws th rlist, invnt in 92, s mtho or onstruting n iint ltriity ntwork in Morvi in th Czh Rpuli. It ws r-invnt mny tims ovr. 8.2. Kruskl s Algorithm As sri in Kruskl s originl ppr, th lgorithm is: Prorm th ollowing stp s mny tims s possil: Among th gs o G not yt hosn, hoos th shortst g whih os not orm ny loops with thos gs lry hosn [Kruskl, 95] In mor morn trminology w woul rpl shortst with lightst n loops with yls. Kruskl s lgorithm is orrt sin it mintins th invrint on h stp tht th gs hosn so r r in th MST o G. This is tru t th strt. Now on h stp, ny g tht orms yl with th lry hosn gs nnot in th MST. This is us ing it woul woul violt th tr proprty o n MST n w know, y th invrint, tht ll th othr gs on th yl r in th MST. Now onsiring th gs tht o not orm yl, th minimum wight g must light g sin it is th lst wight g tht onnts th onnt sugrph t ithr npoint to th rst o th grph. Finlly w hv to rgu tht ll th MST gs hv n. Wll w onsir ll gs, n only toss th ons tht w oul prov wr not in th MST (i.. orm yls with MST gs). W oul inish our isussion o Kruskl s lgorithm hr, ut w wors on how to implmnt th i iintly r wrrnt. In prtiulr hking i n g orms yl might xpnsiv i w r not rul. In it ws not until mny yrs tr Kruskl s originl ppr tht n iint pproh to th lgorithm ws vlop. Not tht to hk i n g (u, v) orms yl, ll on ns to o is tst i u n v r in th sm onnt omponnt s in y th gs lry hosn. On wy to o this is y ontrting n g (u, v) whnvr it is i.., ollps th g n th vrtis u n v into singl suprvrtx. Howvr, i w implmnt this s sri in th lst hptr w woul n to upt ll th othr gs inint on u n v. This n xpnsiv sin n g might n to upt mny tims. To gt roun ths prolm it is possil to upt th gs lzily. Wht w mn y lzily is tht gs inint on ontrt vrtx r not upt immitly, ut rthr ltr whn th g is pross. At tht point th g ns to trmin wht suprvrtis (omponnts) its npoints r in. This i n implmnt with so-ll union-in t typ.

320 CHAPTER 8. MINIMUM SPANNING TREES Algorithm 8.3 (Union-Fin Kruskl). untion kruskl(g = (V, E, w)) = 2 lt 3 vl U = itr UF.insrt UF. V % insrt vrtis into union in strutur 4 vl E = sort(e, w) % sort th gs 5 untion Eg((U, T ), = (u, v)) = lt 7 vl u = UF.in(U, u) 8 vl v = UF.in(U, v) 9 in 0 i (u = v ) thn (U, T ) % i u n v r lry onnt thn skip ls (UF.union(U, u, v ), T ) % ontrt g in U n to T 2 n 3 in 4 itr Eg (U, ) E 5 n Th ADT supports th ollowing oprtions on union-in typ U: insrt(u, v) insrts th vrtx v, union(u, (u, v)) joins th two lmnts u n v into singl suprvrtx, in(u, v) rturns th suprvrtx in whih v longs, possily itsl, n quls(u, v) rturns tru i u n v r th sm suprvrtx. Now w n simply pross th gs in inrsing orr. This i givs Algorithm 8.3. Qustion 8.4. Wht is th work n th spn o Kruskl s lgorithm s on unionin? To nlyz th work n spn o th lgorithm w irst not tht thr is no prlllism, so th spn quls th work. To nlyz th work w n prtition it into th work rquir or sorting th gs n thn th work rquir to itrt ovr th gs using union n in. Th sort rquirs O(m log n) work. Th union n in oprtions n implmnt in O(log n) work h rquiring nothr O(m log n) work sin thy r ll O(m) tims. Th ovrll work is thror O(m log n). It turns out tht th union n in oprtions n tully implmnt with lss thn O(log n) mortiz work, ut this os not ru th ovrll work sin w still hv to sort. 8.2.2 Prim s Algorithm Prim s lgorithm prorms priority-irst srh to onstrut th minimum spnning tr. Th i is tht i w hv lry visit st X, thn y th light-g proprty th minimum wight g with on o its npoint in X n th othr in V \ X must in th MST (it is

8.2. ALGORITHMS FOR MINIMUM SPANNING TREES 32 minimum ross g rom X to V \ X). W n thror it to th MST n inlu th othr npoint in X. This ls to th ollowing inition o Prim s lgorithm: Algorithm 8.5 (Prim s Algorithm). For wight unirt grph G = (V, E, w) n sour s, Prim s lgorithm is priority-irst srh on G strting t n ritrry s V with T =, using priority p(v) = min w(x, v) (to minimiz), n stting x X T = T {(u, v)} whn visiting v whr w(u, v) = p(v). Whn th lgorithm trmints, T is th st o gs in th MST. Exmpl 8.. A stp o Prim s lgorithm. Sin th g (, ) hs minimum wight ross th ut (X, Y ), th lgorithm will visit ing (, ) to T n to X. X 3 Y= V \ X s 5 Exris 8.7. Crully prov th orrtnss o Prim s lgorithm y inution. Intrstingly this lgorithm is quit similr to Dijkstr s lgorithm or shortst pths. Th only irns r () w strt t n ritrry vrtx inst o t sour, (2) tht p(v) = min x X (x, v) inst o min x X ((x) + w(x, v)), n (3) w mintin tr T inst o tl o istns (v). Bus o th similrity w n silly us th sm priority-quu implmnttion s in Dijkstr s lgorithm n it runs with th sm O(m log n) work ouns. Rmrk 8.8. Prim s lgorithm ws invnt in 930 y Czh mthmtiin Vojth Jrnik n ltr inpnntly in 957 y omputr sintist Rort Prim. Esgr Dijkstr s risovr it in 959 in th sm ppr h sri his mous shortst pth lgorithm.

322 CHAPTER 8. MINIMUM SPANNING TREES 8.2.3 Borůvk s Algorithm As isuss in prvious stions, Kruskl n Prim s lgorithm r squntil lgorithms. In this stion, w prsnt n MST lgorithm tht runs iintly in prlll using grph ontrtion. This prlll lgorithm is s on n pproh y Borůvk. As Kruskl s n Prim s, Borůvk s lgorithm onstruts th MST y insrting light gs ut unlik thm, it insrts mny light gs t on. To s how w n slt multipl light gs, rll thn ll light gs tht ross ut must in th MST. Qustion 8.9. Wht is th most trivil ut you n think o? Wht gs ross it? Consir now ut tht is in y vrtx v n th rst o th vrtis in th grph. Th gs tht ross this ut r xtly th gs inint on v. Thror, y th light g rul, or v, th minimum wight g twn it n its nighors is in th MST. Sin this rgumnt pplis to ll vrtis t th sm tim, th minimum wight gs inint n ny vrtx is in th MST. W ll suh gs vrtx-joinrs. Exmpl 8.20. Th vrtx joinrs o th grph r highlight. Th vrtis n oth pik g {, }, piks {, }, n pik {, }, n piks {, }. 2 5 4 7 3 Qustion 8.2. Hv w oun ll th MST gs? Cn w stop? Somtims just on roun o piking vrtx-joinrs will slt ll th MST gs n woul gnrt omplt solution. Howvr, in most ss, th minimum-wight gs on thir own o not orm spnning tr. In th xmpl ov, w th g (, ) is not slt (nithr nor pik it). Qustion 8.22. Givn tht w hv oun som o th gs, how n w pro, n w limint som gs rom onsirtion?

8.2. ALGORITHMS FOR MINIMUM SPANNING TREES 323 To s how w n pro, not tht th vrtx joinrs in prtitoning o th grph ll th vrtis r in prtition. Consir now th gs tht rmin intrnl to prtition. Suh n g is nnot in th MST, us insrting it into th MST woul rt yl. Th gs tht ross th prtitions, howvr, must onsir s thy n in in th MST. Qustion 8.23. How n w limint th intrnl gs? On wy to limint th intrnl gs rom onsirtion, whil kping th ross gs is to prorm grph ontrtion s on th prtitioning in y th vrtx joinrs. Rll tht in grph ontrtion, ll w n is prtitioning o th grph into isjoint onnt sugrphs. Givn suh prtitioning, w thn rpl h sugrph (prtition) with suprvrtx n rll th gs. This is rpt until no gs rmin. Exmpl 8.24. Contrtion long th minimum gs. Not tht thr r runnt gs twn th two prtitions. 7 5 2 3 4? Whn prorming grph ontrtion, w hv to rul out runnt gs. In our isussion o grph ontrtion in Chptr 7, us unwight grphs, w mntion tht w my trt runnt gs irntly s on th pplition. In unwight grphs, th tsk is usully simpl us w n just kp ny on o th runnt gs, n it usully os not mttr whih on. Whn th gs hv wights, howvr, w hv to i to kp ll th gs or slt som o th gs to kp. Qustion 8.25. Whih g shoul w kp or omputing th MST? For th purposs o MST, in prtiulr, w n kp ll th gs or kp just th g with th minimum wight, us th othrs, nnot in th MST. In th xmpl ov, w woul kp th g with wight 4. Wht w just ovr is xtly Borůvk s i. H i not isuss implmnting th ontrtion in prlll. At th tim, thr wr not ny omputrs lt lon prlll ons. W r gl tht h hs lt us somthing to o. In summry, Borůvk s lgorithm n sri s ollows.

324 CHAPTER 8. MINIMUM SPANNING TREES Algorithm 8.2 (Borůvk). Whil thr r gs rmining: () slt th minimum wight g out o h vrtx n ontrt h onnt omponnt in y ths gs into vrtx; (2) rmov sl gs, n whn thr r runnt gs kp th minimum wight g; n (3) ll slt gs to th MST. Cost o Borůvk y using tr ontrtion. W now onsir th iiny o this lgorithm. W irst ous on th numr o rouns o ontrtion n thn onsir how to implmnt th ontrtion. Qustion 8.27. Suppos tht w pik k minimum-wight gs, how mny vrtis will w rmov? Sin ontrting n g rmovs xtly on vrtx (ontrtion o n g n viw s oling on npoint into th othr), i k gs r slt thn k vrtis r rmov. Qustion 8.28. Cn w thn rmov ll th vrtis? It is possil or k = n n to rmov ll th vrtis ut k will gnrlly lss thn n, us two vrtis n slt th sm g. Qustion 8.29. At lst how mny vrtis n rmov? Thror thr must t lst n/2 gs n thus n/2 vrtis will rmov. Consquntly, Borůvk s lgorithm will tk t most log 2 n rouns o slting vrtx-joinrs n ontrting s on th prtitioning in y thm. Qustion 8.30. How n prorm roun o ontrtion s on th prtitioning in y th vrtx-joinrs? Cn w us g ontrtion or str ontrtion? To ontrt th prtition in y th vrtx joinrs, w nnot us g or str ontrtion, us th prtitions my not orrspon to g or str prtitions. In gnrl h prtition intii y slting th vrtx joinrs r nithr singl gs nor singl strs.

8.2. ALGORITHMS FOR MINIMUM SPANNING TREES 325 Exmpl 8.3. An xmpl whr minimum-wight gs giv non-str tr. Not tht w hv in t pik minimum spnning tr y just slting th minimumwight gs. 2 5 3 7 4 It turns out, th minimum-wight gs will orm orst ( st o trs). Thror, th prtitions r in y gnrl trs n thus w wnt to ontrt trs. By rmoving ll gs tht r not vrtx joinrs, w n ontrt prtition y pplying str ontrtion to th prtition. Furthrmor sin whn oing str ontrtion on tr, it rmins tr on h stp, th numr o gs gos own with th numr o vrtis. Thror th totl work to ontrt ll th prtitions is oun y O(n) i using rry squns. Th spn rmins O(log 2 n). Atr ontrting h tr, w hv to upt th gs. As isuss rlir or runnt gs w wnt to kp th minimum wight suh g. Thr r vrious wys to o this, inluing kping th runnt gs. Kping th gs turns out to n tiv solution, n llows th upting th gs to on in O(m) work. Assuming runnt gs, th minimum into h omponnt n still on with O(m) work, s sri low. Sin thr r t most log n rouns, Borůvk s lgorithm will run in O(m log n) work n O(log 3 n) spn. Cost o Borůvk y using str ontrtion. W now sri how to improv th spn o Borůvk y logrithmi tor y intrlving stps o str ontrtion with stps o ining th vrtx joinrs, inst o ully ontrting th trs in y th vrtx-joinrs. Th i is to pply rnomiz str ontrtion on th sugrph inu y th vrtx joinrs, inst o onsiring th whol grph s in onvntionl str ontrtion. Intuitivly, this is orrt us w only hv to r out vrtx joinrs (ll othr gs nnot in th MST). As w will show, on h roun, w will still l to ru th numr o vrtis y onstnt tor (in xpttion), ling to logrithmi numr o totl rouns. Consquntly, w will ru th ovrll spn or ining th MST rom O(log 3 n) to O(log 2 n) n mintin th sm work.

32 CHAPTER 8. MINIMUM SPANNING TREES Exmpl 8.32. An xmpl o Borůvk with str ontrtion. H 7 T 5 H 2 H 4 3 T H H 7 T 5 H 2 H 4 3 T H For st o vrtx-joinrs je, onsir th sugrph H = (V, je) o G n pply on stp o th str ontrtion on H. To pply str ontrtion, w n moiy our strcontrt routin so tht tr lipping oins, th tils only hook ross thir minimum-wight g. Th moii lgorithm or str ontrtion is s ollows. In th o w stns or th wight o th g (u, v). Algorithm 8.33 (Str Contrtion long Vrtx Joinrs). un joinrstrcontrt(g = (V, E), i) = 2 lt 3 vl je = vrtxjoinrs(g) 4 vl P = {u (v, w) je hs(u, i) hs(v, i)} 5 vl V = V \ omin(p ) in (V, P ) n whr vrtxjoinrs(g) ins th vrtx joinrs out o h vrtx v. Bor w go into tils out how w might kp trk o th MST n othr inormtion, lt us try to unrstn wht ts this hng hs on th numr o vrtis ontrt wy. I w hv n non-isolt vrtis, th ollowing lmm shows tht th lgorithm still rmovs n/4 vrtis in xpttion on h stp:

8.2. ALGORITHMS FOR MINIMUM SPANNING TREES 327 Lmm 8.34. For grph G with n non-isolt vrtis, lt X n th rnom vril initing th numr o vrtis rmov y joinrstrcontrt(g, r). Thn, E [X n ] n/4. Proo. Th proo is prtty muh intil to our proo or strcontrt xpt hr w r not working with th whol g st, only rstrit on je. Lt v V (G) non-isolt vrtx. Lik or, lt H v th vnt tht v oms up hs, T v tht it oms up tils, n R v tht v omin(p ) (i., it is rmov). Sin v is non-isolt vrtx, v hs nighors n on o thm hs th minimum wight, so thr xists vrtx u suh tht (v, u) mine. Thn, w hv tht T v H u implis R v sin i v is til n u is h, thn v must join u. Thror, Pr [R v ] Pr [T v ] Pr [H u ] = /4. By th linrity o xpttion, w hv tht th numr o rmov vrtis is [ ] E I {R v } = E [I {R v }] n/4 v:v non-isolt sin w hv n vrtis tht r non-isolt. v:v non-isolt This mns tht this MST lgorithm will tk only O(log n) rouns, just lik our othr grph ontrtion lgorithms. Finl Things. Thr is littl it o trikinss sin, s th grph ontrts, th npoints o h g hngs. Thror, i w wnt to rturn th gs o th minimum spnning tr, thy might not orrspon to th originl npoints. To l with this, w ssoit uniqu ll with vry g n rturn th tr s st o lls (i.. th lls o th gs in th spnning tr). W lso ssoit th wight irtly with th g. Th typ o h g is thror (vrtx vrtx wight ll), whr th two vrtx npoints n hng s th grph ontrts ut th wight n ll stys ix. This ls to th slightlyupt vrsion o joinrstrcontrt tht pprs in Algorithm 8.35. Th untion vrtxjoinr(g) in Lin ins th minimum g out o h vrtx v n mps v to th pir onsisting o th nighor long th g n th g ll. By Lmm 8., sin ll ths gs r minimum out o th vrtx, thy r s to to th MST. Lin 2 thn piks rom ths gs th gs tht go rom til to h, n thror gnrts mpping rom tils to hs long minimum gs, rting strs. Finlly, Lin 3 rmovs ll vrtis tht r in this mpping to str ntrs. This is ry to us in th MST o, similr to th grphcontrt o stui lst tim, xpt w rturn th st o lls or th MST gs inst o th rmining vrtis. Th o is givn in Algorithm 8.35 Th MST lgorithm is ll y running MST(G,, r). As n si, w know tht T is spnning orst on th ontrt nos. Finlly w sri how to implmnt minegs(g), whih rturns or h vrtx th minimum g inint on tht vrtx. Thr r vrious wys to o this. On wy is to mk

328 CHAPTER 8. MINIMUM SPANNING TREES Algorithm 8.35 (Borůvk s s on Str Contrtion). untion vrtxjoinrs (E) = 2 lt 3 ET = {(u, v, w, l) {u (v, w, l)} : (u, v, w, l) E} 4 untion joinegs((v, w, l ), (v 2, w 2, l 2 )) = 5 i (w w 2 ) thn (v, w, l ) ls (v 2, w 2, l 2 ) in 7 ru (mrg joinegs) {} ET 8 n 9 untion joinrstrcontrt(g = (V, E), i) 0 lt mine = vrtxjoinrs(g) 2 P = {(u (v, w, l)) mine hs(u, i) hs(v, i)} 3 V = V \ omin(p ) 4 in (V, P ) n 5 untion MST((V, E), T, i) = i ( E = 0) thn T 7 ls lt 8 (V, P T ) = joinrstrcontrt((v, E), i) 9 P = {u v : u (v, w, l) P T } {v v : v V } 20 T = {l : u (v, w, l) P T } 2 E = {(P [u], P [v], w, l) : (u, v, w, l) E P [u] P [v]} 22 in 23 MST((V, E ), T T, i + ) 24 n singlton tl or h g n thn mrg ll th tls with n pproprit untion to rsolv ollisions. Algorithm 8.35 givs o tht mrgs gs y tking th on with lightr g wight. I using squns or th gs n vrtis n vn simplr wy is to prsort th gs y rsing wight n thn us injt. Rll tht whn thr r ollisions t th sm lotion injt will lwys tk th lst vlu, whih will th on with minimum wight. 8.3 Minimum Spnning Trs n th Trvl Slsprson Prolm Bouning TSP with MST. Thr is n intrsting onntion twn minimum spnning trs n th symmtri Trvling Slsprson Prolm (TSP), n NP-hr prolm. Rll

8.3. MINIMUM SPANNING TREES AND THE TRAVEL SALESPERSON PROBLEM329 tht in TSP prolm, w r givn st o n itis (vrtis) n r intrst in ining tour tht visits ll th vrtis xtly on n rturns to th origin. For th symmtri s th gs r unirt (or quivlntly th istn is th sm in h irtion). For th TSP prolm, w usully onsir omplt grphs, whr thr is n g twn ny two vrtis. Evn i grph is not omplt, w n typilly omplt it y insrting gs with lrg wights tht mk sur tht th g nvr pprs in solution. Hr w lso ssum th g wights r non-ngtiv. Qustion 8.3. Cn you think o wy to oun th solution to TSP prolm on n unirt onnt grph using minimum spnning trs. Sin th solution to th TSP prolm visits vry vrtx on (rturning to th origin), it spns th grph. It is howvr not tr ut yl. Sin h vrtx is visit on, howvr, ropping ny g woul yil spnning tr. Thus solution to th TSP prolm nnot hv lss totl wight thn tht o minimum spnning tr. In othr wors, th wight o MST yils lowr oun on th solution to th symmtri TSP prolm or grphs with non-ngtiv g wights. Approximting TSP with MST. It turns out tht minimum spnning trs n lso us to in n pproximt solutions to th TSP prolm, tivly ining n uppr oun. This, howvr, rquirs on mor onition on th MST prolm. In prtiulr in ition to rquiring tht wights r non-ngtiv w rquir tht ll istns stisy th tringl inqulity i.., or ny thr vrtis,, n, w(, ) w(, ) + w(, ). This rstrition hols or most pplitions o th TSP prolm n is rrr to s th mtri TSP prolm. It lso implis tht g wights r non-ngtiv. W woul now lik wy to us th MST to gnrt pth to tk s n pproximt solution to th TSP prolm. To o this w irst onsir pth s on th MST tht n visit vrtx multipl tims, n thn tk shortuts to nsur w only visit h vrtx on. Qustion 8.37. Givn n unirt grph G, suppos tht you omput minimum spnning tr T. Cn you us th tr to visit h vrtx in th grph rom givn origin? Givn minimum spnning tr T w n strt t ny vrtx s n tk pth s on th pth-irst srh on th tr rom s. In prtiulr whnvr w visit nw vrtx v rom vrtx u w trvrs th g rom u to v n whn w r on visiting vrything rhl rom v w thn k up on this sm g, trvrsing it rom v to u. This wy vry g in our pth is trvrs xtly twi, n w n th pth t our initil vrtx. I w viw h unirt g s two irt gs, thn this pth is so-ll Eulr tour o th tr i.. yl in grph tht visits vry g xtly on. Sin T spns th grph, th Eulr tour will visit vry vrtx t lst on, ut possily multipl tims.

330 CHAPTER 8. MINIMUM SPANNING TREES Exmpl 8.38. Th igur on th right shows n Eulr tour o th tr on th lt. Strting t, th tour visits,,,,,,,,,,. Now, rll tht in th TSP prolm it is ssum tht thr is n g twn vry pir o vrtis. Qustion 8.39. Cn you in wy to riv non-optiml solution to TSP using th prtiulr pproh to visiting vrtis? Lt s irst try to limint multipl visits. Sin it is possil to tk n g rom ny vrtx to ny othr, w n tk shortuts to voi visiting vrtis multipl tims. Mor prisly wht w n o is whn out to go k to vrtx tht th tour hs lry visit, inst in th nxt vrtx in th tour tht hs not n visit n go irtly to it. W ll this shortut g. Exmpl 8.40. Th igur on th right shows solution to TSP with shortuts, rwn in r. Strting t, w n visit,,,,,,. Qustion 8.4. Assuming tht gs r istns twn itis, n w sy nything out th lngths o th shortut gs? By th tringl inqulity th shortut gs r no longr thn th pths tht thy rpl. Thus y tking shortuts, th totl istn is not inrs.

8.4. EXERCISES AND PROBLEMS 33 Qustion 8.42. Wht n you sy out th wight o th TSP tht w otin in this wy? Sin th Eulr tour trvrss h g in th minimum spnning tr twi (on in h irtion), th totl wight o th pth is xtly twi th wight o th TSP. With shortuts, w otin solution to th TSP prolm tht is t most th wight o th Eulr tour, n hn t most twi th wight o th MST. Sin th wight o th MST is lso lowr oun on th TSP, th solution w hv oun is within tor o 2 o optiml. This mns our pproh is n pproximtion lgorithm or TSP tht pproximts th solution within tor o 2. This n summriz s: W (MST(G)) W (TSP(G)) 2W (MST(G)). Rmrk 8.43. It is possil to ru th pproximtion tor to.5 using wll known lgorithm vlop y Nios Christois t CMU in 97. Th lgorithm is lso s on th MST prolm, ut is ollow y ining vrtx mthing on th vrtis in th MST with o-gr, ing ths to th tr, ining n Eulr tour o th omin grph, n gin shortutting. Christois lgorithm ws on o th irst pproximtion lgorithms n it took ovr 40 yrs to improv on th rsult, n only vry slightly. 8.4 Exriss n Prolms Exris 8.44. Prov tht ny tr with n vrtis hs n gs. Exris 8.45. Work out th tils o th lgorithm or spnning trs using grph ontrtion with str prtitions (s mntion in Stion 8.) n prov tht it prous spnning tr. Exris 8.4. Prov tht th ntwork with th minimum ost in Exmpl 8.7 is in n MST o th grph. Exris 8.47. Writ out th psuoo or Priority Quu s implmnttion o Prim s lgorithm tht runs in O(m log n) work. Prolm 8.48. Prov tht grph with istint g wights hs uniqu minimum spnning tr.

332 CHAPTER 8. MINIMUM SPANNING TREES Prolm 8.49. Prov tht th vrtx-joinrs slt in ny roun Borůvk s lgorithm orm orst. Rll tht w r ssuming tht no two g wights r qul.