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

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

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

CS 241 Analysis of Algorithms

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

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

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

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

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

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

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

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

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

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

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

1 Introduction to Modulo 7 Arithmetic

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

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

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

QUESTIONS BEGIN HERE!

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

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

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

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

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

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

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

Round 7: Graphs (part I)

Present state Next state Q + M N

CS September 2018

Constructive Geometric Constraint Solving

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

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

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

QUESTIONS BEGIN HERE!

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

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

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

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

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

Trees as operads. Lecture A formalism of trees

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

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

Multipoint Alternate Marking method for passive and hybrid performance monitoring

Outline. Binary Tree

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

Seven-Segment Display Driver

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

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

EE1000 Project 4 Digital Volt Meter

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

Designing A Concrete Arch Bridge

Planar Upward Drawings

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

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

Problem solving by search

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

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

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

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

COMP108 Algorithmic Foundations

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

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

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

Numbering Boundary Nodes

Graph Contraction and Connectivity

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

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

OpenMx Matrices and Operators

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

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

Chapter 9. Graphs. 9.1 Graphs

Garnir Polynomial and their Properties

Solutions to Homework 5

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

Scientific Programming. Graphs

12. Traffic engineering

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

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

GREEDY TECHNIQUE. Greedy method vs. Dynamic programming method:

Two Approaches to Analyzing the Permutations of the 15 Puzzle

This chapter covers special properties of planar graphs.

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

Lecture 20: Minimum Spanning Trees (CLRS 23)

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

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?

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

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

Analysis for Balloon Modeling Structure based on Graph Theory

Walk Like a Mathematician Learning Task:

Aquauno Video 6 Plus Page 1

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

(4, 2)-choosability of planar graphs with forbidden structures

Strongly connected components. Finding strongly-connected components

Decimals DECIMALS.

Solutions for HW9. Bipartite: put the red vertices in V 1 and the black in V 2. Not bipartite!

Applications: The problem has several applications, for example, to compute periods of maximum net expenses for a design department.

CS 103 BFS Alorithm. Mark Redekopp

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

Transcription:

Dv Mount CMSC 45: Ltur Grph Bsis Thursy, Au, 07 Rin: Chpt. in KT (Klinr n Tros) n Chpt. in DBV (Dsupt, Ppimitriou, n Vzirni). Som o our trminoloy irs rom our txt. Grphs n Dirphs: A rph G = (V, E) is strutur tht rprsnts isrt st V ojts, ll vrtis or nos, n st o pirwis rltions E twn ths ojts, ll s. Es my irt rom on vrtx to nothr or my unirt. Th trm rph mns n unirt rph, n irt rphs r otn ll irphs (s Fi. ). Grphs n irphs provi lxil mthmtil mol or numrous pplition prolms involvin inry rltionships twn isrt olltion o ojt. Exmpls o rph pplitions inlu ommunition n trnsporttion ntworks, soil ntworks, loi iruits, sur mshs us or shp sription in omputr-i sin n orphi inormtion systms, prn onstrints in shulin systms. (Unirt) Grph Dirph Fi. : Grphs n irphs. Dinition: An unirt rph (or simply rph) G = (V, E) onsists o init st V n st E o unorr pirs o istint vrtis. Dinition: A irt rph (or irph) G = (V, E) onsists o init st V n st E o orr pirs o vrtis. Osrv tht multipl s twn th sm two vrtis r not llow, ut in irt rph, it is possil to hv two oppositly irt s twn th sm pir o vrtis. For unirt rphs, sl-loop s r not llow, ut thy r llow or irt rphs. Dirt rphs n unirt rphs r irnt ojts mthmtilly. Crtin notions (suh s pth) r in or oth, ut othr notions (suh s onntivity n spnnin trs) my in only or on. Grph n Dirph Trminoloy: Givn n = (u, v) in irph, w sy tht u is th oriin o n v is th stintion o. Givn n = {u, v in n unirt rph, u n v r ll th npoints o. Th is inint on (mnin tht it touhs) oth u n v. Givn two vrtis in rph or irph, w sy tht vrtx v is jnt to vrtx u i thr is n {u, v (or rphs) or (u, v) (or irphs). In irph, th numr o s omin out o v is ll its out-r, not out-(v), n th numr o s omin in is ll its in-r, not in-(v). In n unirt Ltur Fll 07

Dv Mount rph w just tlk out th r o vrtx s th numr o inint s, not (v). Whn isussin th siz o rph, w typilly onsir oth th numr o vrtis n th numr o s. Th numr o vrtis is typilly writtn s n, n th numr o s is writtn s m. (Bwr: Thr r mny irnt onvntions. Th numr o vrtis my xprss s n, v, V, or V, n th numr o s my xprss s m,, E, or E. Hr r som si omintoril ts out rphs n irphs. W will lv th proos to you. Givn rph with n vrtis n m s thn: In rph: Numr o s: 0 m ( n ) = n(n )/ = O(n ). Sum o rs: v V (v) = m. In irph: Numr o s: 0 m n. Sum o rs: v V in-(v) = v V out-(v) = m. Noti tht nrlly th numr o s in rph my s lr s qurti in th numr o vrtis. Howvr, th lr rphs tht ris in prti typilly hv muh wr s. A rph is si to sprs i m is O(n), n ns, othrwis. Whn ivin th runnin tims o lorithms, w will usully xprss it s untion o oth n n m, so tht th prormn on sprs n ns rphs will pprnt. Pths n Cyls: A pth in rph or irph is squn o vrtis v 0,..., v k suh tht (v i, v i ) is n or i =,..., k. Th lnth o th pth is th numr o s, k. A pth is simpl i ll vrtis n ll th s r istint. A yl is pth ontinin t lst on n or whih v 0 = v k. A yl is simpl i its vrtis (xpt v 0 n v k ) r istint, n ll its s r istint. A rph or irph is si to yli i it ontins no simpl yls. An yli onnt rph is ll r tr or simply tr or short (s Fi. ). (Th trm r is intn to mphsiz th t tht th tr hs no root, in ontrst to root tr, s is usully sn in t struturs.) An yli unirt rph (whih n not onnt) is olltion o r trs, n is ll orst. An yli irph is ll irt yli rph, or DAG or short (s Fi. ). (Fr) Tr DAG Biprtit rph Fi. : Illustrtion o ommon rph trms. Ltur Fll 07

Dv Mount A iprtit rph is on in whih th vrtis o rph n prtition into two isjoint susts, not V n V, suh tht ll th s hv on npoint in V n on in V (s Fi. ). Not tht vry yl in iprtit rph ontins n vn numr o s. W sy tht w is rhl rom u i thr is pth rom u to w. Not tht vry vrtx is rhl rom itsl y trivil pth tht uss zro s. An unirt rph is onnt i vry vrtx n rh vry othr vrtx. (Conntivity is it mssir or irphs, n w will in it ltr.) Th susts o mutully rhl vrtis prtition th vrtis o th rph into isjoint susts, ll th onnt omponnts o th rph. In irphs th notion o rhility is it irnt, us it is possil or u to rh w ut not vi vrs. A irph is si to stronly onnt i or h u n w, thr is pth rom u to w n pth rom w to u. Rprsnttions o Grphs n Dirphs: Thr r two ommon wys o rprsntin rphs n irphs. First w show how to rprsnt irphs. Lt G = (V, E) irph with n = V n lt m = E. W will ssum tht th vrtis o G r inx {,,..., n. Ajny Mtrix: An n n mtrix in or v, w n. { i (v, w) E A[v, w] = 0 othrwis. (S Fi..) I th irph hs wihts w n stor th wihts in th mtrix. For xmpl i (v, w) E thn A[v, w] = W (v, w) (th wiht on (v, w)). I (v, w) / E thn nrlly W (v, w) n not in, ut otn w st it to som spil vlu,.. A(v, w) =, or. (By w mn som numr whih is lrr thn ny llowl wiht.) It miht om s surpris, ut thr r numr o intrstin rltionships twn th us o mtris to rprsnt rphs n th mtris tht ris in linr lr to rprsnt linr trnsormtions. For xmpl, th invlus o th jny mtrix o rph provi lot o inormtion out th strutur o th rph. Ajny List: An rry Aj[... n] o pointrs whr or v n, Aj[v] points to list (.., sinly or ouly link list) ontinin th vrtis tht r jnt to v (i.., th vrtis tht n rh rom v y sinl ). I th s hv wihts thn ths wihts my lso stor in th link list lmnts (s Fi. ). Aj 0 0 0 0 Ajny mtrix Ajny list Fi. : Ajny mtrix n jny list or irphs. Ltur Fll 07

Dv Mount W n rprsnt unirt rphs usin xtly th sm rprsnttion, ut w will stor h twi. In prtiulr, w rprsntin th unirt {v, w y th two oppositly irt s (v, w) n (w, v) (s Fi. 4). Noti tht vn thouh w rprsnt unirt rphs in th sm wy tht w rprsnt irphs, it is importnt to rmmr tht ths two lsss o ojts r mthmtilly istint rom on nothr. This n us som omplitions. For xmpl, suppos you writ n lorithm tht oprts y mrkin s o rph. You n to rul whn you mrk (v, w) in th rprsnttion tht you lso mrk (w, v), sin thy r oth th sm in rlity. Whn lin with jny lists, it my not onvnint to wlk own th ntir link list, so it is ommon to inlu ross links twn orrsponin s. 4 4 4 0 0 0 0 0 0 0 0 Ajny mtrix 4 Aj 4 4 Ajny list (with rosslinks) Fi. 4: Ajny mtrix n jny list or rphs. An jny mtrix rquirs Θ(n ) stor, n n jny list rquirs Θ(n+m) stor. Th n riss us thr is on ntry or h vrtx in Aj. Sin h list hs out-(v) ntris, whn this is summ ovr ll vrtis, th totl numr o jny list rors is Θ(m). For most pplitions, th jny list rprsnttion is stnr. Dpth-First Srh: On o th most importnt si oprtions on rph is to systmtilly visit ll its vrtis. Ths trvrsls ntully impos typ o tr strutur (or nrlly orst) on th rph, n trs r usully muh sir to rson out thn nrl rphs. W r ivn rph G = (V, E), whih my irt or unirt. W mploy our uxiliry rrys. To voi rvisitin th sm vrtx, w mintin mrk or h vrtx: unisovr, isovr, inish. Aitionl inormtion n stor s prt o th trvrsl pross: Disovry tim: [u] inits th tim whn vrtx u ws isovr, whih oinis with th momnt tht th DFS pross is strt t this vrtx. Finish tim: [u] inits th tim whn vrtx u is inish prossin. At this point, ll o u s nihorin nos hv n visit, n in, vrythin rhl rom u hs n isovr n possily inish. Prssor pointr: p[u] inits th vrtx tht isovr u. Eh o th orm (p[u], u) is tr in th DFS rursion tr. DFS inus tr strutur. In orr to hnl instns whr not ll vrtis r rhl rom th strtin vrtx, w inlu min prorm tht invoks DFS whnvr n unisovr vrtx is nountr. Th min prorm is shown in o lok low n th Ltur 4 Fll 07

Dv Mount rursiv DFSvisit untion is shown in th nxt o lok. (Fi. 5 illustrts th xution on n unirt rph, n Fi. 6 shows n xmpl on irt rph.) DFS(G) { tim = 0 or h (u in V) mrk[u] = unisovr Dpth-First Srh (Min Prorm) // min prorm // initiliztion or h (u in V) i (mrk[u] == unisovr) DFSVisit(u) // unisovr vrtx? //...strt nw srh hr DFSVisit(u) { mrk[u] = isovr [u] = ++tim or h (v in Aj(u)) { i (mrk[v] == unisovr) { pr[v] = u DFSVisit(v) mrk[u] = inish [u] = ++tim DFS Visit (Pross sinl no) // prorm DFS srh t u // u hs n isovr // unisovr nihor? //...visit it // w r on with u Anlysis: Th runnin tim o DFS is O(n + m). W ll o th nlysis or unirt rphs. First osrv tht i w inor th tim spnt in th rursiv lls, th min DFS prour runs in O(n) tim. Eh vrtx is visit xtly on in th srh, n hn th ll DFSVisit() is m xtly on or h vrtx. W n just nlyz h on iniviully n up thir runnin tims. Inorin th tim spnt in th rursiv lls, w n s tht h vrtx u n pross in O( + (u)) tim (th + is n in s th r is 0). Thus th totl tim us in th prour is T (n) = n + ( ) ( + (u)) = n + (u) + n = n + m = O(n + m). u V u V A similr nlysis hols i w onsir DFS or irphs. Prnthsis Lmm n E Typs: DFS nturlly imposs tr strutur (tully olltion o trs, or orst) on th strutur o th rph. This is just th rursion tr, whr th (u, v) riss whn prossin vrtx u w ll DFSVisit(v) or som nihor v. Th hirrhil strutur nturlly imposs nstin strutur on th isovry-inish tim intrvls. This is sri in th ollowin lmm (n illustrt in Fi. 7()). Ltur 5 Fll 07

Dv Mount G : visit(s) s s /.. visit() visit() s /.. /.. /.. visit() visit() 4/.. 5/.. s /.. /.. /.. rturn rturn visit() s /.. 4/7 5/6 /.. /.. 8/.. visit() visit() 4/7 5/6 s /.. /.. /.. rturn rturn... rturn s 8/.. 9/.. 0/.. s /6 /5 4/7 8/ 5/6 9/ 0/ Fi. 5: Dpth-irst srh on n unirt rph. (Blu nos r isovr, n pink nos r inish. Eh no u is ll with th vlus [u]/[u].) G : visit() visit() visit() /.. /.. rturn rturn /.. /5 visit() visit() /.. /5 rturn rturn rturn 6/.. visit() visit() rturn /0 rturn /0 6/9 6/9 /5 /5 /4 / /.. 7/.. 7/8 7/8 Fi. 6: Dpth-irst srh on irt rph. (Blu nos r isovr, n pink nos r inish. Eh no u is ll with th vlus [u]/[u].) Ltur 6 Fll 07

Dv Mount Lmm: (Prnthsis Lmm) Givn rph G = (V, E) (irt or unirt), n ny DFS tr or G n ny two vrtis u, v V : u is snnt o v i [[u], [u]] [[v], [v]]. u is n nstor o v i [[u], [u]] [[v], [v]]. u n v r unrlt (in trms o nstor/snnt) i [[u], [u]] n [[v], [v]] r isjoint. /5 /0 6/9 7/8 /4 / tr orwr k ross 4 5 6 7 8 9 0 4 () () Fi. 7: () th Prnthsis Lmm n () th DFS typs. Th strutur o th rminin (non-tr) s o th rph pn on th typ o rph involv. For unirt rphs, th rminin s r ll k s. An importnt osrvtion is tht or h k (u, v), u is ithr propr nstor or propr snnt o v. To s why, onsir ny non-tr (u, v). Sin th rph is unirt, w my ssum without loss o nrlity tht u ws isovr or v. By th prnthsis lmm, this mns ithr tht u is n nstor o v (n w r on) or tht thir isovryinish intrvls r isjoint. I thy r isjoint, u must inish or v is isovr. Howvr, this is impossil, us s w r prossin u, w will s th (u, v) n thus isovr v. For irt rphs th non-tr s o th rph n lssii s ollows (S Fi. 7()): Bk s: (u, v) whr v is (not nssrily propr) nstor o u in th tr. (Thus, sl-loop is onsir to k.) Forwr s: (u, v) whr v is propr snnt o u in th tr. Cross s: (u, v) whr u n v r not nstors or snnts o on nothr (in t, th my o twn irnt trs o th orst). It is not iiult to lssiy th s o DFS tr on-th-ly y nlyzin th vrtx sttus (unisovr, isovr, inish) n/or onsirin th tim stmps. (This is lt s n xris.) B rul, howvr. Rmmr tht in n unirt rph, vry is rprsnt twi. Whn lssiyin k s, you shoul sur tht you r not sin th othr hl o tr. Ltur 7 Fll 07