Graph Contraction and Connectivity

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

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

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

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

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

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

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

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

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

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

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

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

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

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

CS 241 Analysis of Algorithms

Planar Upward Drawings

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

Constructive Geometric Constraint Solving

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

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

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

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

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

1 Introduction to Modulo 7 Arithmetic

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

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

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

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

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

COMP108 Algorithmic Foundations

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

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

Present state Next state Q + M N

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

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

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

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

Garnir Polynomial and their Properties

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

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

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

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

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

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

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

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

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?

Trees as operads. Lecture A formalism of trees

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

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

QUESTIONS BEGIN HERE!

Solutions to Homework 5

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

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

Seven-Segment Display Driver

12. Traffic engineering

QUESTIONS BEGIN HERE!

Numbering Boundary Nodes

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

Minimum Spanning Trees

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

EE1000 Project 4 Digital Volt Meter

CS September 2018

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

Designing A Concrete Arch Bridge

DUET WITH DIAMONDS COLOR SHIFTING BRACELET By Leslie Rogalski

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

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

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

Problem solving by search

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

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

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

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

Complete Solutions for MATH 3012 Quiz 2, October 25, 2011, WTT

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

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

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

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

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

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

Chapter 9. Graphs. 9.1 Graphs

Computational Biology, Phylogenetic Trees. Consensus methods

Section 3: Antiderivatives of Formulas

More Foundations. Undirected Graphs. Degree. A Theorem. Graphs, Products, & Relations

Graph Theory. Vertices. Vertices are also known as nodes, points and (in social networks) as actors, agents or players.

ECE 407 Computer Aided Design for Electronic Systems. Circuit Modeling and Basic Graph Concepts/Algorithms. Instructor: Maria K. Michael.

Formal Concept Analysis

Decimals DECIMALS.

Outline. Binary Tree

On Local Transformations in Plane Geometric Graphs Embedded on Small Grids

GREEDY TECHNIQUE. Greedy method vs. Dynamic programming method:

CMSC 451: Lecture 2 Graph Basics Thursday, Aug 31, 2017

Jonathan Turner Exam 2-10/28/03

Construction 11: Book I, Proposition 42

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

CSI35 Chapter 11 Review

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

Transcription:

Chptr 17 Grph Contrtion n Conntivity So r w hv mostly ovr thniqus or solving prolms on grphs tht wr vlop in th ontxt o squntil lgorithms. Som o thm r sy to prllliz whil othrs r not. For xmpl, w sw tht BFS hs som prlllism sin h lvl n xplor in prlll, ut thr ws no prlllism in DFS. 1 Thr ws lso limit prlllism in Dijkstr s lgorithm, ut thr ws plnty o prlllism in th Bllmn-For lgorithm. In this hptr w will ovr thniqu ll grph ontrtion tht ws spiilly sign to us in prlll lgorithms n llows us to gt polylogrithmi spn or rtin grph prolms. 17.1 Prliminris n Grph Prtitioning Pls rviw th mtril on grphs (Stion 2.4) or proing with th rst o this hptr, spilly th stions on sugrphs n onntivity. Rll tht prtitioning o st S is st T o susts o S suh tht h lmnt o S is in xtly on sust t T. W rr to h lmnt o T s prtition n th st T s prtitioning o S. A vrtx prtitioning o grph is prtitioning o its vrtx st. In th ontxt o grph prtitioning, w rr to h sugrph inu y sust o th vrtis s prtition. W n lso in g prtitioning o grph similrly. In this hptr, w r only onrn with vrtx prtitioning o grphs; w thror us th trm grph prtitioning to rr to vrtx-prtitioning o grph. In grph prtitioning, w n istinguish twn two kins o gs: intrnl gs n ross gs. Intrnl gs r gs tht r within prtition; ross gs r gs tht r twn prtitions. On wy to prtition grph is to mk h onnt omponnt prtition. In suh prtitioning, thr r no ross gs twn th prtitions. 1 In rlity, thr is prlllism in DFS whn grphs r ns in prtiulr, lthough vrtis n to visit squntilly, with som r, th gs n pross in prlll. 295

296 CHAPTER 17. GRAPH CONTRACTION AND CONNECTIVITY Somtims it is usul to giv nm or ll to h prtition. A prtitioning o grph n thn sri s st o nms or th prtitions n prtition mp tht mps h vrtx to th nm o its prtition. Th nms n hosn ritrrily, though somtims it is onptully n omputtionlly sir to us vrtx insi prtition s nm (rprsnttiv) or tht prtition. Exmpl 17.1. Th prtitioning o th vrtis {{,, }, {}, {, }} ins thr prtitions s vrtx-inu sugrphs. Th gs {, }, {, }, n {, } r intrnl gs, n th gs {, }, {, }, {, } n {, } r ross gs. Hving nm th thr prtitions, n, w n spiy this prtitioning with ollowing prtition mp: ({,, }, {,,,,, }) In our xmpl, w gv rsh nms to suprvrtis. It is otn mor onvnint to pik rprsnttiv rom h prtition inst o rsh nm. W n thn rprsnt th prtitioning s mpping rom h vrtx to its rprsnttiv (suprvrtx). For xmpl, w n rprsnt th prtitioning in th xmpl with th ollowing pir onsisting o th nms or st o prtitions n th prtition mp ({,, }, {,,,,, }). 17.2 Grph Contrtion Grph ontrtion is thniqu or omputing proprtis o grph in prlll. As its nm implis, it is ontrtion thniqu, whr w solv prolm y ruing to smllr instn o th sm prolm. Qustion 17.2. Cn w solv grph prolms using ivi-n-onqur? Grph ontrtion is spilly importnt us ivi-n-onqur is iiult to pply to grphs iintly. Th iiulty is tht ivi-n-onqur woul rquir rlily prtitioning th grph into smllr grphs. Du to thir irrgulr strutur, grphs r iiult to prtition. In t, grph prtitioning prolms r typilly NP-hr.

17.2. GRAPH CONTRACTION 297 In th rst o this stion, w sri th grph-ontrtion sign thniqu n sri two pprohs to ontrting grphs y using g prtitionings n str prtitionings, rily rrr to s g ontrtion n str ontrtion. 17.2.1 Th Dsign Thniqu As with th ontrtion thniqu tht w hv sn in Chptr 6, grph-ontrtion n us to solv vrity o grph prolms. Th ky i hin grph ontrtion is to shrink th input grph, illy y onstnt tor in siz so tht w n solv th prolm on smllr grph, n thn us th solution to th smllr grph to onstrut th solution or th input grph. This thniqu n sri s n inutiv lgorithm-sign thniqu (Dsign Thniqu 17.3). Algorithm-Dsign Thniqu 17.3 (Grph Contrtion). Bs s : For smll nough grph (.g. no gs rmining), lult th sir rsult irtly. Inutiv s : Contrt th grph into smllr grph, illy onstnt rtion smllr. Rurs on th smllr grph. Us th rsult rom th rursion long with th initil grph to lult th sir rsult. Th ky stp o grph ontrtion is th ontrtion o th grph into smllr grph. Qustion 17.4. Any is out how w might ontrt grph? On wy to ontrt grph is to mp it to smllr grph y mpping susts o vrtis, s in y prtitioning, to vrtis in smllr grph s ollows. 1. Comput vrtx-prtitioning or th grph. 2. Contrt h prtition into singl vrtx, ll suprvrtx. 3. Drop gs intrnl to prtition. 4. Rrout ross gs to orrsponing suprvrtis.

298 CHAPTER 17. GRAPH CONTRACTION AND CONNECTIVITY By slting prtitioning to gui th ontrtion, w mk sur tht h vrtx in th grph is mpp to on uniqu vrtx in th smllr grph (us prtitions r isjoint n thy inlu ll th vrtis). Givn prtitioning, w ontrt th grph y ontrting h prtition into singl vrtx n upting th gs. Mor spiilly, w rt supr vrtx or h prtition. W thn onsir h g in th grph. I th g is intrnl to prtition, w skip it. I it is ross g, w rt nw g twn th suprvrtis rprsnting th prtitions o th vrtis o th g. On inl point tht w hv to rul is uplit gs: sin thr n mny ross gs twn two prtitions, w my n up rting multipl gs twn two suprvrtis. W n rmov suh gs or lv thm in. This pross o intiying prtition n upting th gs is ll roun o grph ontrtion. In grph ontrtion, rouns r rpt until thr r no gs lt. Exmpl 17.5. On roun o grph ontrtion illustrt. Intiy prtitons Contrt Dlt uplit gs Contrting grph own to singl vrtx in thr rouns: Roun 1 Roun 3 Roun 2 17.2.2 Eg Prtitioning n Eg Contrtion In g prtitoning, w slt h prtition to ithr singl vrtx or two vrtis onnt y n g. A grph ontrtion whr prtitions r slt y g prtitioning is rrr to

17.2. GRAPH CONTRACTION 299 s g ontrtion. Exmpl 17.6. An xmpl g prtitioning in whih vry prtition onsists o two vrtis n n g twn thm. This prtitioning will ru th grph to hl its siz tr ontrtion. Contrt Not tht in gnrl w nnot just hv pirs o vrtis sin th grph might not hv n vn numr o vrtis, ut vn i it os (no pun intn), it is likly tht it nnot prtition into st o pirs join y gs. W thror will stisi y som st o isjoint gs (gs tht o not shr n npoint). Fining suh st is ommon tsk in vrity o grph lgorithms, n hn hs nm. Dinition 17.7. A vrtx mthing or n unirt grph G = (V, E) is sust o gs M E suh tht no two gs in M shr n npoint. Exmpl 17.8. A vrtx mthing or our vorit grph (highlight gs) n th orrsponing prtitions. It ins our prtitions (irl), two o thm in y th gs in th mthing, {, } n {, }, n two o thm r th lt ovr vrtis n. Rmrk 17.9. Th prolm o ining th lrgst vrtx mthing or grph is ll th mximum vrtx mthing prolm. It is wll stui prolms n thr r svrl intrsting lgorithms or th prolm, inluing on tht n solv th prolm in O( V E ) work. For grph ontrtion, w o not n mximum mthing ut on tht it is suiintly lrg.

300 CHAPTER 17. GRAPH CONTRACTION AND CONNECTIVITY Qustion 17.10. Cn you sri n lgorithm or ining vrtx mthing? On wy to in vrtx mthing is to go through th gs on y on mintining n initilly mpty st M n or h g, i no g in M is lry inint on its npoints thn it to M, othrwis toss it. Th prolm with this pproh is tht it is squntil sin h ision pns on prvious isions. Qustion 17.11. Cn you think o wy to in vrtx mthing in prlll? I w wnt to in th vrtx mthing in prlll w will likly n to mk lol isions t h vrtx. On possiility is in or h vrtx in prlll to pik on o its nighors to pir up with. Qustion 17.12. Wht is th prolm with this pproh? Th prolm with this pproh is tht multipl vrtis might pik gs tht onnt to th sm othr vrtx. W thror n wy to rk th symmtry tht riss whn two vrtis try to pir up with th sm vrtx. Qustion 17.13. Cn you think o wy to us rnomiztion to rk this symmtry? It turns out tht w n us rnomiztion to rk th symmtry. On pproh or intiying vrtx mthing in prlll is to lip oin or h g n pik th g i it lips hs n ll th gs inint on its npoints lip tils. This gurnts tht no two gs inint on th sm vrtx r slt. Lt us nlyz how tiv this pproh is in slting rsonly lrg st o gs. W irst onsir yl grphs, onsisting o singl yl n no othr gs. In suh grph vry vrtx hs xtly two nighors. Exmpl 17.14. A grph onsisting o singl yl. T T H H T T Eh g lips oin tht oms up ithr hs (H) or tils (T ). W pik n g i it turns up hs n ll othr gs inint on its npoints r tils. In th xmpl th gs {, } n {, } r slt.

17.2. GRAPH CONTRACTION 301 W wnt to trmin th proility tht n g is slt in suh grph. Sin th oins r lipp inpnntly t rnom, n th vrtis t h npoint h hv on othr nighor, th proility tht n g piks hs n its two nighoring gs pik tils is 1 1 1 2 2 = 1. W now wnt to nlyz how mny gs r slt in xpttion. Lt R 2 8 n initor rnom vril noting whthr is slt or not, tht is R = 1 i is slt n 0 othrwis. Rll tht th xpttion o initor rnom vrils is th sm s th proility it hs vlu 1 (tru). Thror w hv E[R ] = 1/8. Thus summing ovr ll gs, w onlu tht xpt numr o gs lt is m (not, m = n in yl grph). 8 In th hptr on rnomiz lgorithms Stion 9.3 w rgu tht i h roun o n lgorithm shrinks th siz y onstnt rtion in xpttion, n i th rnom hois in th rouns r inpnnt, thn th lgorithm will inish in O(log n) rouns with high proility. Rll tht ll w n to o is multiply th xpt rtion tht rmin ross rouns n thn us Mrkov s inqulity to show tht tr som k log n rouns th proility tht th prolm siz is lst 1 is vry smll. For yl grph, this thniqu ls to n lgorithm or grph ontrtion with linr work n O(log 2 n) spn lt s n xris. Qustion 17.15. Cn you think o wy to improv th xpt numr o gs lt? Thr r svrl wys to improv th numr o lt gs. On wy is or h g to pik on o its nighors n to slt n g (u, v) i it ws pik y oth u n v. In th s o irl, this inrss th xpt numr o lt gs to m. Anothr wy is lt h 4 g pik rnom numr in som rng n thn slt n g i it is th lol mximum, i.., it pik th highst numr mong ll th gs inint on its n points. This inrss th xpt numr o gs ontrt in irl to m. 3 Although g prtitioning works quit wll with yl grphs, or squntilly with th pproprit t struturs, w shoul sk i it works wll in prlll with ritrry grphs? Unortuntly it os not. Th prolm is tht only on g inint on vrtx n ontrt on h roun. Thror vrtis with high grs, will hv to ontrt thir nighors on t tim. For xmpl, onsir th ollowing kin o grph, ll str grph. Exmpl 17.16. A str grph with ntr v n ight stllits. v Mor prisly, w n in str grph s ollows.

302 CHAPTER 17. GRAPH CONTRACTION AND CONNECTIVITY Dinition 17.17 (Str Grph). A str grph G = (V, E) is n unirt grph with ntr vrtx v V, n st o gs E tht tth v irtly to th rst o th vrtis, ll stllits, i.. E = {{v, u} : u V \ {v}}. Not tht singl vrtx n singl g r oth str grphs. It is not iiult to onvin ourslvs tht on str grph with n vrtis 1 ntr n n 1 stllits ny g prtitioning lgorithm will tk Ω(n) rouns. To ix this prolm w n to l to orm prtitions tht onsist o mor thn just gs. Rmrk 17.18. An strt t typ ll isjoint sts is otn us to ontrt grphs squntilly. Disjoint sts supply two untions: union, whih joins two omponnts, n in, whih ins wht omponnt vrtx is in. In our rmwork, th union oprtion is simply g ontrtion ross singl g, n th in is just lookup in th prtition mp. Smntilly or prtition mp P w n in union s: union(p, u, v) = {u i (v = u) thn v ls v : (u v ) P } whr hr w hv m v th nw rprsnttiv o th suprvrtx {u, v}, n hv upt ll vrtis tht us to point to u to now point to v. Implmnting th union this wy, howvr, is iniint sin it n rquir upting lot o vrtis. It turns out tht th oprtions n n implmnt muh mor iintly. In on n implmnt t strutur tht only rquirs mortiz O(α(n)) work pr oprtion, whr α(n) (th invrs Akrmnn untion) is untion tht is vry los ot O(1), n n is th numr o oprtions. 17.2.3 Str Prtitioning n Str Contrtion Sin prtitions must isjoint, g prtitioning prvnts ontrting th grph signiintly, us i w slt n g inint on vrtx v s prtition, thn non o th othr gs inint on tht vrtx n thir own prtition. This is unmntl limittion, us grphs n hv high-gr vrtis. Thus, to in thniqu tht works mor roly, w n to llow or high-gr vrtis to prt o prtition. W onsir mor ggrssiv orm o prtitoning ll str prtitioning, whr prtitions r trmin y slting strs. For xmpl in Exmpl 17.16, th whol grph n singl prtition. W rr to grph ontrtion whr prtitions r slt y strt prtitioning n str ontrtion.

17.2. GRAPH CONTRACTION 303 Exmpl 17.19. In th grph low (lt), w n in 2 isjoint strs (right). Th ntrs r highlight (with olor whit), th rst o th vrtis r stllits. Intrnl gs, whih will rsi insi prtition n will rmov uring ontrtion, r rwn in shs; ross gs rmin soli. Not tht th intrnl gs o h str is not lwys qul to th gs o th str. Qustion 17.20. How n w str prtition grph? As with g prtitioning, it is possil to onstrut str prtitionings squntilly. For xmpl, w n strt with n ritrry vrtx n tth ll its nighors to str. W woul thn rmov th str rom th grph, n rpt (until ll vrtis r ount or) y piking nothr ritrry vrtx. Not tht vrtx is th simplst orm o str. So i w hv isolt vrtis rmining thy orm trivil strs. Qustion 17.21. How n w str prtition grph? W n lso onstrut str prtitionings in prlll y mking lol inpnnt isions in prlll. As in g prtitionings, w n us rnomiztion to rk symmtry. Qustion 17.22. Cn you think o rnomiz pproh or slting strs? For xmpl, to trmin th ntrs, w n lip oin or h vrtx. I th oin oms up hs, tht vrtx is th ntr o str. W n thn mk vrtx tht hs lipp tils stllit y tthing it to on o its nighors tht is ntr. I no suh nighor xists (ll nighors hv lipp tils) thn w mk th vrtx ntr s wll. I vrtx hs multipl ntrs s nighors, w n pik on ritrrily. This pproh my not optiml in th sns tht it my not rt th smllst numr o strs ut this is ptl or our purposs, us w r only intrst in ruing th siz o th ontrt grph y onstnt tor not minimizing it.

304 CHAPTER 17. GRAPH CONTRACTION AND CONNECTIVITY Algorithm 17.24 (Str Prtition). 1 untion strprtition(g = (V, E), i) = 2 lt 3 % slt gs tht go rom stllit to ntr 4 vl TH = {(u, v) E hs(u, i) hs(v, i)} 5 % Us tl mrg to mk mpping rom stllits to ntrs, rmoving uplits 6 vl P = (u,v) TH {u v} 7 % Th suprvrtis ntrs n unmth stllits 8 vl V = V \ omin(p ) 9 % Mp suprvrtis to thmslvs 10 vl P = {u u : u V } 11 in (V, P P ) n Exmpl 17.23. An xmpl str prtition. Vrtis tht lipp hs om ntrs (vrtis,. A vrtx (vrtis n ) tht lipp tils ttmpts to om stllit y ining ntr mong its nighors, rking tis ritrrily. I non xist (xmpl: vrtx ), it oms ntr. W n up orming thr prtitions th str with ntr (with no stllits), th str with ntr (with two stllits), n th singlton. H T H T T H T H T T oin lips hoos strs rsulting prtitions Bor sriing th lgorithm or prtitioning grph into strs, w n to sy oupl wors out th sour o rnomnss. Wht w will ssum is tht h vrtx is givn (potntilly ininit) squn o rnom n inpnnt oin lips. Th i th lmnt o th squn n ss hs(v, i) : V Z B. Th untion rturns tru i th i th lip on vrtx v is hs n ls othrwis. Sin most mhins on t hv tru sours o rnomnss, in prti this n implmnt with psuornom numr gnrtor or vn with goo hsh untion. Th lgorithm or str prtitioning is givn in Algorithm 17.24. It tks in grph n roun numr, n rturns grph prtitioning o th sort rturn y prtitiongrph. Th

17.2. GRAPH CONTRACTION 305 lgorithm lips oins on h vrtx n slts th irt gs tht point rom til (stllit) to h (ntr) this givs TH. In this st o gs thr might multipl gs rom th sm stllit n w wnt to hoos on o thm. Lin 6 os this y rting st o singlton tls n mrging thm. In prtiulr th union is shorthn or th ollowing mrg: St.Ru (Tl.mrg (n (x,y) x)) {{u v} : (u, v) TH } This tivly is or h stllit on o th ntrs it will point to. All th ntrs n ny potntil stllits tht o not gt mpp to ntr, sin thy o not nighor ntr, r mpp to thmslvs (Lin 10). Finlly w mrg th tl or th rmpp stllits n th othr vrtis. Exmpl 17.25. Rturning to Exmpl 17.23 n ssuming th sm lips s givn in tht xmpl, w hv tht: TH = {(, ), (, ), (, )}. Ths r th (irt) gs rom stllits to ntrs. Now w onvrt h g into singlton mp, n mrg thm into th mpping: P = {, }. Not tht th g (, ) hs n rmov sin th mrging o th mp slts only on lmnt or h ky in th omin. Now or ll rmining vrtis V = V \ omin(p ) = {,, } w mp thm to thmslvs, giving: P = {,, }. Th P n P r mrg to giv th inl mpping: P P = {,,,, }. Anlysis o Str Prtitioning. Whn th strs oun y strprtition r ontrt, h str oms on vrtx, so th numr o vrtis rmov is th siz o P. In xpttion, how ig is P? Th ollowing lmm shows tht on grph with n non-isolt vrtis, th siz o P or th numr o vrtis rmov in on roun o str ontrtion is t lst n/4 in xpttion. Lmm 17.26. For grph G with n non-isolt vrtis, lt X n th rnom vril initing th numr o vrtis rmov y strprtition(g, r). Thn, E [X n ] n/4.

306 CHAPTER 17. GRAPH CONTRACTION AND CONNECTIVITY Proo. Consir ny non-isolt vrtx v V (G). Lt H v th vnt tht vrtx v oms up hs, T v tht it oms up tils, n R v tht v omin(p ) (i., it is rmov). By inition, w know tht non-isolt vrtx v hs t lst on nighor u. So, w hv tht T v H u implis R v sin i v is til n u is h v must ithr join u s str or som othr str. Thror, Pr [R v ] Pr [T v ] Pr [H u ] = 1/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 Cost Spiition 17.27 (Str Prtitioning). Bs on rry-s ost spiition or squns n singl-tr squns, th ost o strprtition is O(n+m) work n O(log n) spn or grph with n vrtis n m gs. 17.3 Conntivity vi Grph Contrtion An importnt, wll-stui prolm, ll (grph) onntivity prolm, is to trmin th onnt omponnts o grph. Prolm 17.28 (Th Grph Conntivity (GC) Prolm). Givn n unirt grph G = (V, E) rturn ll o its onnt omponnts (mximl onnt sugrphs). A grph onntivity lgorithm woul rturn th onnt omponnts o grph, y or xmpl spiying th st o vrtis in h omponnt. Qustion 17.29. Cn you solv th grph-onntivity prolm y using on o th thniqus rntly ovr in this lss? Th grph onntivity prolm n solv y using grph srh. In prtiulr, w n strt t ny vrtx n in, using DFS or BFS, ll vrtis rhl rom it to rt th irst omponnt. W thn mov onto th nxt vrtx n i it hs not lry n srh, srh rom it to rt th son omponnt, n so on w rpt until w xhustivly onsir ll th vrtis. Qustion 17.30. Woul ths pprohs yil goo prlllism? Wht woul th spn o th lgorithm?

17.3. CONNECTIVITY VIA GRAPH CONTRACTION 307 Using grph srh ls to prtly snsil squntil lgorithms or grph onntivity, ut thy r not goo prlll lgorithms. Rll tht DFS hs linr spn. Qustion 17.31. How out BFS? Do you rll th spn o BFS? BFS tks spn proportionl to th imtr o th grph. In th ontxt o our lgorithm th spn woul th imtr o omponnt (th longst istn twn two vrtis). Qustion 17.32. How lrg n th imtr o omponnt? Cn you giv n xmpl? Th imtr o omponnt n s lrg s n 1. A hin o n vrtis will hv imtr n 1. Qustion 17.33. How out in ss whn th imtr is smll, or xmpl whn th grph is just isonnt olltion o gs. Whn th imtr o grph is smll, w my us BFS to prorm h grph srh, ut w still hv to itrt ovr th omponnts on y on. Thus th spn in th worst s n linr in th numr o omponnts, whih n lrg. W woul lik to in prlll lgorithm or onntivity tht hs smll spn n ll grphs. To this n, w will us th grph-ontrtion thniqu with str prtitioning. To spiy th lgorithm, w will us n g-st rprsnttion or grphs, whr vry g is rprsnt s pir o vrtis, in oth orrs. This is tivly quivlnt to irt grph rprsnttion o unirt grphs with two rs pr g. Exmpl 17.34. Th rprsnttion o n unirt grph s st o orr pirs, with h g ppring in oth irtions. V = {,,,,, } E = {(, ), (, ), (, ), (, ), (, ), (, ), (, ), (, ), (, ), (, )} W n now writ givn n lgorithm s on grph ontrtion tht ounts th numr o onnt omponnts in grph (Algorithm 17.35. Eh ontrtion on Lin 4 rturns th

308 CHAPTER 17. GRAPH CONTRACTION AND CONNECTIVITY Algorithm 17.35 (Counting Componnts using Grph Contrtion). 1 untion ountcomponnts(g = (V, E)) = 2 i E = 0 thn V 3 ls lt 4 (V, P ) = strprtition(v, E) 5 E = {(P [u], P [v]) : (u, v) E P [u] P [v]} 6 in 7 ountcomponnts(v, E ) 8 n st o suprvrtis V n tl P mpping vry v V to v V. Lin 5 upts ll gs so tht th two npoints r in V y looking thm up in P : this is wht (P [u], P [v]) is. Sonly it rmovs ll sl gs: this is wht th iltr P [u] P [v] os. On th gs r upt, th lgorithm rurss on th smllr grph. Th trmintion onition is whn thr r no gs. At this point h omponnt hs shrunk own to singlton vrtx. Exmpl 17.36. Th vlus o V, P, n E tr h roun o th ontrtion shown in Exmpl 17.5. V = {,, } roun 1 P = {,,,,, } E = {(, ), (, ), (, ), (, ), (, ), (, )} V = {, } roun 2 P = {,, } E = {(, ), (, )} V = {} roun 3 P = {, } E = {} Our prvious lgorithm just ount th numr o omponnts. It turns out w n moiy th lgorithm slightly to omput th omponnts thmslvs inst o rturning thir ount. To this n, w r going to onstrut th mpping rom vrtis to thir omponnts rursivly. This is possil us w n otin th mpping y omposing th mpping rom vrtis to thir suprvrtis n th mpping rom suprvrtis to thir omponnts, whih w otin rursivly. Algorithm 17.37 shows th lgorithm.

17.3. CONNECTIVITY VIA GRAPH CONTRACTION 309 Algorithm 17.37 (Contrtion-s grph onntivity). 1 untion onntcomponnts(g = (V, E)) = 2 i E = 0 thn (V, {v v : v V }) 3 ls lt 4 vl (V, P ) = strprtition(v, E) 5 vl E = {(P [u], P [v]) : (u, v) E P [u] P [v]} 6 vl (V, P ) = onntcomponnts(v, E ) 7 in 8 (V, {v P [s] : (v s) P }) 9 n Exmpl 17.38. onntcomponnts might rturn: ({}, {,,,,, }) sin thr is singl omponnt n ll vrtis will mp to tht omponnt ll. In this s ws pik s th rprsnttiv, ut ny o th initil vrtis is vli rprsnttiv, in whih s ll vrtis woul mp to it. Th only irns rom ountcomponnts r moiition to th s s, n th xtr lin (Lin 8) tr th rursiv ll. In th s s inst o rturning th siz o V rturns ll vrtis in V long with mpping rom h on to itsl. This is vli nswr sin i thr r no gs h vrtx is its own omponnt. In th inutiv s, whn rturning rom th rursion, Lin 8 upts th mpping P rom vrtis to suprvrtis y looking up th omponnt tht th suprvrtx longs to, whih is givn y P. This simply involvs th look up P [s] or vry (v s) P. Not tht i you viw mpping s untion, thn this is quivlnt to untion omposition, i.. P P.

310 CHAPTER 17. GRAPH CONTRACTION AND CONNECTIVITY Exmpl 17.39. Consir our xmpl grph (Exmpl 17.38), n ssum tht strprtition rturns: V = {,, } P = {,,,,, }. Sin th grph is onnt, th rursiv ll to onntcomponnts(v, E ) will mp ll vrtis in V to th sm vrtx. Lts sy this vrtx is giving: V = {} P = {,, }. Now {v P [s] : (v s) P } will or h vrtx-suprvrtx pir in P, look up wht tht suprvrtx got mpp to in th rursiv ll. For xmpl, vrtx mps to vrtx in P so w look up in P, whih givs us so w know tht is in th omponnt. Ovrll th rsult is: {,,,,, }. Now lts nlyz th ost o ountcomponnts n onntcomponnts whn using strprtition. Lt n n th numr o non-isolt vrtis. Noti tht on vrtx oms isolt (u to ontrtion), it stys isolt until th inl roun (ontrtion only rmovs gs). Thror, w hv th ollowing spn rurrn (w ll look t work ltr): S(n n ) = S(n n) + O(log n) whr n n = n n X n X is th numr o vrtis rmov (s in rlir in th lmm out strprtition). But E [X] = n n /4 so E [n n] = 3n/4. This is milir rurrn, whih w know solvs to O(log 2 n n ), n thus O(log 2 n). As or work, illy, w woul lik to show tht th ovrll work is linr sin w might hop tht th siz is going own y onstnt rtion on h roun. Unortuntly, this is not th s. Although w hv shown tht on n rmov onstnt rtion o th non-isolt vrtis on on str ontrt roun, w hv not shown nything out how mny gs w rmov. W n rgu tht th numr o gs rmov is t lst qul to th numr o vrtis sin rmoving stllit lso rmovs th g tht tths it to its str s ntr. But this os not hlp symptotilly oun th numr o gs rmov. Consir th ollowing

17.3. CONNECTIVITY VIA GRAPH CONTRACTION 311 squn o rouns: roun vrtis gs 1 n m 2 n/2 m n/2 3 n/4 m 3n/4 4 n/8 m 7n/8 In this xmpl, it is lr tht th numr o gs os not rop low m n, so i thr r m > 2n gs to strt with, th ovrll work will O(m log n). In, this is th st oun w n show symptotilly. To oun th work, w will onsir non-isolt n isolt vrtis sprtly. For th non-isolt vrtis, w hv th ollowing work rurrn: W (n n, m) W (n n, m) + O(n n + m), whr n n is th rmining numr o non-isolt vrtis s in in th spn rurrn. This solvs to E [W (n n, m)] = O(n n + m log n n ) = O(n + m log n). To oun th work on isolt vrtis, w not tht thr t most n o thm t h roun n thus, th itionl work is O(n log n). This nlysis givs us th ollowing thorm. Thorm 17.40. For grph G = (V, E), ountcomponnts using strprtition grph ontrtion with n rry squn works in O( V + E log V ) work n O(log 2 V ) spn. Rmrk 17.41. In gnrl th grph ontrtion thniqus os not spiy how to prorm th prtitioning n t h stp. For xmpl, in this hptr, w ovr two thniqus or prtitioning. Dpning on th prolm, othr thniqus n us s wll. For grph ontrtion to pplil to prolm, howvr, it is importnt tht th grph ontrt t h roun stisy rtin proprtis. For xmpl, whn solving grph onntivity with th lgorithms sri hr, w hv to rul tht th prtitioning mintins onntivity: omponnt shoul onnt tr roun o grph ontrtion i n only i it ws onnt or th roun. To nsur this, w will n to us prtitioning lgorithm tht nsurs tht h prtition is onnt. For xmpl, o th prtitionings o th grphs shown low, th son on os not mintin onntivity, whrs th irst on os. Th prtitioning on th lt is pproprit or grph ontrtion sin h prtition is onnt. Th prtition on th right is not sin is not onnt to n.

312 CHAPTER 17. GRAPH CONTRACTION AND CONNECTIVITY 17.4 Tr Contrtion Our nlysis in th prvious stion ws or gnrl grphs. Wht i w r ontrting orst o trs inst. Rll tht n unirt grph is orst i it hs no yls n is tr i it hs no yls n is onnt. A tr on n vrtis lwys hs xtly n 1 gs, n orst hs t most n 1 gs. Sin it hs no yls, str is tr. Th sm onntcomponnts lgorithm s on str prtitoning n us or orst or tr ut with trs, th work oun is ttr. This is us th numr o gs is orst is nvr mor thn th numr o vrtis, n hn th numr o gs rs gomtrilly (in xpttion) in h roun, s o th numr o vrtis. Th ovrl xpt work is thror gomtri sum o th orm: E [W (n, m)] = i=0 ( ) i 3 kn = O(n), 4 inst o O(m log n) or gnrl grphs. Th spn is not t. For grph G = (V, E) onsir sust o gs T E tht orms orst (i.. hs no yl). Suh sust ins prtitioning o th orginl grph, whr h tr is its own prtition. Thror on wy to ontrt grph is to intiy suh sust T, n thn us onntcomponnts(v, T ), whih os linr work s xplin ov, inst o our strprtition routin. W will us this i in n lgorithm or Minimum Spnning Trs sri in Chptr 18. Exmpl 17.42. A grph n sust o th gs T (in ol) tht in st o thr isjoint trs, h implying prtition: g i g i g h j h j i I w run onntcomponnts on T (th mil igrm) w r lt with th sir prtitioning with suprvrtis {, g, i} n th mpping: {,,,,,, g g, h i, i u, j i} This n us to ontrt th originl grph wht is shown on th right.

17.5. EXERCISES AND PROBLEMS 313 17.5 Exriss n Prolms Exris 17.43. Thr r 18 sugrphs or tringl onsisting o thr vrtis n thr gs onnting thm, inluing th mpty grph n th grph itsl. List thm ll. Exris 17.44. In str ontrtion, wht is th proility tht vrtx with gr is rmov. Exris 17.45. Fin n xmpl grph, whr str-s grph ontrtion rmovs smll numr o gs on h roun.

314 CHAPTER 17. GRAPH CONTRACTION AND CONNECTIVITY.