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

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

CS 241 Analysis of Algorithms

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

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

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

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

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

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

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

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

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

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

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

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

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

Outline. Circuits. Euler paths/circuits 4/25/12. Part 10. Graphs. 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?

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

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

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

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

COMP108 Algorithmic Foundations

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

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

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

Scientific Programming. Graphs

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

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

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

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

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

Round 7: Graphs (part I)

Planar Upward Drawings

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

CSI35 Chapter 11 Review

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

Problem solving by search

QUESTIONS BEGIN HERE!

Analysis of Algorithms - Elementary graphs algorithms -

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

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

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

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

Constructive Geometric Constraint Solving

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

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

Analysis of Algorithms - Elementary graphs algorithms -

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

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

Graphs and Graph Searches

GREEDY TECHNIQUE. Greedy method vs. Dynamic programming method:

12. Traffic engineering

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

1 Introduction to Modulo 7 Arithmetic

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

Minimum Spanning Trees

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

Numbering Boundary Nodes

Computational Biology, Phylogenetic Trees. Consensus methods

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

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

QUESTIONS BEGIN HERE!

Walk Like a Mathematician Learning Task:

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

Outline. Binary Tree

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

CS553 Lecture Register Allocation I 3

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

Aquauno Video 6 Plus Page 1

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

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

Seven-Segment Display Driver

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

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

Lecture 20: Minimum Spanning Trees (CLRS 23)

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

Chapter 9. Graphs. 9.1 Graphs

Present state Next state Q + M N

CIT 596 Theory of Computation 1. Graphs and Digraphs

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

Analysis for Balloon Modeling Structure based on Graph Theory

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

Garnir Polynomial and their Properties

Plan. I Gale-Shapley Running Time. I Graphs. I Motivation and definitions I Graph traversal: BFS and DFS

(Minimum) Spanning Trees

CS 103 BFS Alorithm. Mark Redekopp

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

CS September 2018

Graph Contraction and Connectivity

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

Strongly connected components. Finding strongly-connected components

Section 3: Antiderivatives of Formulas

Trees as operads. Lecture A formalism of 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?

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

The Plan. Honey, I Shrunk the Data. Why Compress. Data Compression Concepts. Braille Example. Braille. x y xˆ

arxiv: v1 [cs.ds] 20 Feb 2008

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

Last time: introduced our first computational model the DFA.

Transcription:

s s of s Computr Sin & Enginring 423/823 Dsign n Anlysis of Ltur 03 (Chptr 22) Stphn Sott (Apt from Vinohnrn N. Vriym) s of s s r strt t typs tht r pplil to numrous prolms Cn ptur ntitis, rltionships twn thm, th gr of th rltionship, t. This hptr ovrs sis in grph thory, inluing rprsnttion, n lgorithms for si grph-thorti prolms W ll uil on ths ltr this smstr s of s A (simpl, or unirt) grph G =(V,E) onsists of V, nonmpty st of vrtis n E st of unorr pirs of istint vrtis ll gs A D B E C V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)} 1/29 2/29 3/29 s (2) s (3) of s s of s A irt grph (igrph) G =(V,E) onsists of V, nonmpty st of vrtis n E st of orr pirs of istint vrtis ll gs s of s A wight grph is n unirt or irt grph with th itionl proprty tht h g hs ssoit with it rl numr w() ll its wight 3-6 12 7 0 s of s Ajny Two ommon wys of rprsnting grph: Ajny list n jny mtrix Lt G =(V,E) grph with n vrtis n m gs 3 4 Othr vritions: multigrphs, psuogrphs, t. 4/29 5/29 6/29

Ajny (BFS) s of s Ajny For h vrtx v 2 V, stor list of vrtis jnt to v For wight grphs, informtion to h no How muh is sp rquir for storg? s of s Ajny Us n n n mtrix M, whrm(i, j) =1if (i, j) is n g, 0 othrwis If G wight, stor wights in th mtrix, using 1 for non-gs How muh is sp rquir for storg? 0 1 1 1 0 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 1 1 0 s of s Givn grph G =(V,E) (irt or unirt) n sour no s 2 V, BFS systmtilly visits vry vrtx tht is rhl from s Uss quu t strutur to srh in rth-first mnnr Crts strutur ll BFS tr suh tht for h vrtx v 2 V, th istn (numr of gs) from s to v in tr is th shortst pth in G Initiliz h no s olor to whit As no is visit, olor it to gry () in quu), thn lk () finish) 7/29 8/29 9/29 BFS(G, s) BFS Exmpl BFS Exmpl (2) for h vrtx u 2 V \{s} o 1 olor[u] =whit 2 [u] =1 3 [u] =nil s of s 4 n 5 olor[s] =gry 6 [s] =0 7 [s] =nil 8 Q = ; 9 Enquu(Q, s) 10 whil Q 6= ; o 11 u = Dquu(Q) 12 for h v 2 Aj[u] o 13 if olor[v] ==whit thn 14 olor[v] =gry 15 [v] =[u] +1 16 [v] =u 17 Enquu(Q, v) s of s s of s 18 19 n 20 olor[u] =lk 21 n 10 / 29 11 / 29 12 / 29

BFS Proprtis (DFS) DFS(G) s of s Wht is th running tim? Hint: How mny tims will no nquu? Aftr th n of th lgorithm, [v] =shortst istn from s to v ) Solvs unwight shortst pths Cn print th pth from s to v y rursivly following [v], [ [v]], t. If [v] ==1, thn v not rhl from s ) Solvs rhility s of s Anothr grph trvrsl lgorithm Unlik BFS, this on follows pth s p s possil for ktrking Whr BFS is quu-lik, DFS is stk-lik Trks oth isovry tim n finishing tim of h no, whih will om in hny ltr s of s for h vrtx u 2 V o 1 olor[u] =whit 2 [u] =nil 3 n 4 tim =0 5 for h vrtx u 2 V o 6 if olor[u] ==whit thn 7 DFS-Visit(u) 8 9 n 13 / 29 14 / 29 15 / 29 DFS-Visit(u) DFS Exmpl DFS Exmpl (2) s of s olor[u] =gry 1 tim = tim +1 2 [u] =tim 3 for h v 2 Aj[u] o 4 if olor[v] ==whit thn 5 [v] =u 6 DFS-Visit(v) 7 8 n 9 olor[u] =lk 10 f[u] =tim = tim +1 s of s s of s 16 / 29 17 / 29 18 / 29

DFS Proprtis DFS Proprtis (2) Applition: s of s 19 / 29 Tim omplxity sm s BFS: ( V + E ) Vrtx u is propr snnt of vrtx v in th DF tr i [v] <[u] <f[u] <f[v] ) Prnthsis strutur: If on prints (u whn isovring u n u) whn finishing u, thn print txt will wll-form prnthsiz sntn s of s 20 / 29 Clssifition of gs into groups A tr g is on in th pth-first forst A k g (u, v) onnts vrtx u to its nstor v in th DF tr (inlus slf-loops) A forwr g is nontr g onnting no to on of its DF tr snnts A ross g gos twn non-nstrl gs within DF tr or twn DF trs S lls in DFS xmpl Exmpl us of this proprty: A grph hs yl i DFS isovrs k g (pplition: lok ttion) Whn DFS first xplors n g (u, v), look t v s olor: olor[v] ==whit implis tr g olor[v] ==gry implis k g olor[v] ==lk implis forwr or ross g s of s 21 / 29 A irt yli grph (g) n rprsnt prns: n g (x, y) implis tht vnt/tivity x must our for y Applition: (2) Algorithm Applition: s of s A topologil sort of g G is n linr orring of its vrtis suh tht if G ontins n g (u, v), thnu pprs for v in th orring s of s 1 Cll DFS lgorithm on g G 2 As h vrtx is finish, insrt it to th front of link list 3 Rturn th link list of vrtis s of s Givn irt grph G =(V,E), strongly onnt omponnt (SCC) of G is mximl st of vrtis C V suh tht for vry pir of vrtis u, v 2 Cuis rhl from v n v is rhl from u Thus topologil sort is sning sort of vrtis s on DFS finishing tims Why os it work? Whn no is finish, it hs no unxplor outgoing gs; i.. ll its snnt nos r lry finish n insrt t ltr spot in finl sort 22 / 29 23 / 29 24 / 29 Wht r th SCCs of th ov grph?

Trnspos SCC Algorithm SCC Algorithm Exmpl s of s Our lgorithm for fining SCCs of G pns on th trnspos of G, not G T G T is simply G with gs rvrs Ft: G T n G hv sm SCCs. Why? s of s 1 Cll DFS lgorithm on G 2 Comput G T 3 Cll DFS lgorithm on G T, looping through vrtis in orr of rsing finishing tims from first DFS ll 4 Eh DFS tr in son DFS run is n SCC in G s of s Aftr first roun of DFS: Whih no is first on to visit in son DFS? 25 / 29 26 / 29 27 / 29 SCC Algorithm Exmpl (2) SCC Algorithm Anlysis s of s Aftr son roun of DFS: s of s Wht is its tim omplxity? How os it work? 1 Lt x no with highst finishing tim in first DFS 2 In G T, x s omponnt C hs no gs to ny othr omponnt (Lmm 22.14), so th son DFS s tr gs fin xtly x s omponnt 3 Now lt x 0 th nxt no xplor in nw omponnt C 0 4 Th only gs from C 0 to nothr omponnt r to nos in C, so th DFS tr gs fin xtly th omponnt for x 0 5 An so on... 28 / 29 29 / 29