DFS on Directed Graphs BOS. Outline and Reading ( 6.4) Digraphs. Reachability ( 6.4.1) Directed Acyclic Graphs (DAG s) ( 6.4.4)

Size: px
Start display at page:

Download "DFS on Directed Graphs BOS. Outline and Reading ( 6.4) Digraphs. Reachability ( 6.4.1) Directed Acyclic Graphs (DAG s) ( 6.4.4)"

Transcription

1 S on irected Graphs OS OR JK SO LX W MI irected Graphs S Outline and Reading ( 6.4) Reachability ( 6.4.1) irected S Strong connectivity irected cyclic Graphs (G s) ( 6.4.4) Topological Sorting irected Graphs S igraphs digraph is a graph whose edges are all directed Short for directed graph pplications one-way streets flights task scheduling irected Graphs S 1.3 3

2 igraph pplication Scheduling: edge (a,b) means task a must be completed before b can be started ics21 ics22 ics23 ics51 ics53 ics52 ics161 ics131 ics141 ics121 ics11 ics151 The good life irected Graphs S irected S S on digraphs traverses edges only along their proper direction In the directed S algorithm, we have four types of edges discovery edges back edges forward edges cross edges directed S starting at a vertex s determines the vertices reachable from s irected Graphs S irected S example S_Sweep starts at, then, tree, back, cross irected Graphs S 1.3 6

3 Gs and Topological Ordering directed acyclic graph (G) is a digraph that has no directed cycles topological ordering of a digraph is a numbering v 1,, v n of the vertices such that for every edge (v i, v j ), we have i < j xample: in a task scheduling digraph, a topological ordering a task sequence that satisfies the v 2 precedence constraints Theorem digraph admits a topological v ordering if and only if it is a G 1 irected Graphs S 1.3 G G v 4 v 5 v 3 Topological ordering of G Topological Sorting Number vertices, so that (u,v) in implies u < v 1 wake up typical student day 2 3 eat study computer sci. play make cookies for professors 4 5 nap more c.s. write c.s. program 10 sleep 6 work out 11 dream about graphs irected Graphs S 1.3 lgorithm for Topological Sorting Note: This algorithm is different than the one in Goodrich-Tamassia Method TopologicalSort(G) H G // Temporary copy of G n G.numVertices() while H is not empty do Let v be a vertex with no outgoing edges Label v n n n - 1 Remove v from H Running time: O(n + m) [with smart implementation] How? irected Graphs S 1.3

4 Topological Sorting lgorithm using S Simulate the algorithm by using depth-first search lgorithm topos_sweep(g) Input dag G Output topological ordering of G n G.numVertices() for all u G.vertices() setlabel(u, UNXPLOR) for all e G.edges() setlabel(e, UNXPLOR) for all v G.vertices() if getlabel(v) = UNXPLOR topologicals(g, v) O(n+m) time. lgorithm topologicals(g, v) Input graph G and a start vertex v of G Output a labeling of the vertices of G in the connected component of v in topological order setlabel(v, VISIT) for all e G.outIncidentdges(v) if getlabel(e) = UNXPLOR w opposite(v,e) if getlabel(w) = UNXPLOR setlabel(e, ISOVRY) topologicals(g, w) else {e is a forward or cross edge} setlabel(e, VISIT) Label v with topological number n n n - 1 irected Graphs S Topological Sorting xample irected Graphs S Topological Sorting xample irected Graphs S

5 Topological Sorting xample irected Graphs S Topological Sorting xample irected Graphs S Topological Sorting xample 6 irected Graphs S

6 Topological Sorting xample 6 5 irected Graphs S Topological Sorting xample irected Graphs S Topological Sorting xample irected Graphs S 1.3 1

7 Topological Sorting xample irected Graphs S Topological Sorting xample irected Graphs S Strong onnectivity ach vertex can reach all other vertices a c g d e f b irected Graphs S

8 Strong onnectivity lgorithm Pick a vertex v in G. Perform a S from v in G. If there s a w not visited, print no. Let G be G with edges reversed. Perform a S from v in G. If there s a w not visited, print no. G: a f d c e g b lse, print yes. G : a c g Running time: O(n+m). d e f b irected Graphs S Strongly onnected omponents Maximal subgraphs such that each vertex can reach all other vertices in the subgraph an be computed in O(n+m) time using S a c g { a, c, g } f d e b { f, d, e, b } irected Graphs S S algorithm Using S_Sweep for directed graphs, construct list L of reverse finish order of the vertices in the traversal. Node is finished when traversal leaves it permanently. o another S_Sweep on G R, (G with edges reversed), with the following modification: in S_Sweep outer loop, start S calls on vertices according to the order in list L. ach spanning tree produced by S_Sweep on G R will contain all nodes from exactly one S of G irected Graphs S

9 Strongly onnected omponents irected Graphs S Strongly onnected omponents irected Graphs S S lgorithm, more detail // Phase 1 Run S_Sweep on G, returning a list L of nodes in reverse finish order. one by adding vertex v to the front of L after traversal on v is finished in S_Sweep. // Phase 2a onstruct G R from G by copying the vertices, and then adding the reverse of every edge from G to G R. // Phase 2b o a modified S_Sweep traversal on G R, where list L is used to order the S calls. ach S call labels vertices traversed with a different S number. // inal Phase: Label vertices and edges of G. irected Graphs S 1.3 2

10 S Phase 1 onstruct list L Similar to topological sort lgorithm S1S_Sweep(G) Input dag G Output list L of vertices of G in reverse finish order. L empty list for all u G.vertices() setlabel(u, UNXPLOR) for all e G.edges() setlabel(e, UNXPLOR) for all v G.vertices() if getlabel(v) = UNXPLOR S1S(G, v) O(n+m) time. lgorithm S1S(G, v) Input graph G and a start vertex v of G Output vertices of G in the connected component of v added to L, according to reverse finish order setlabel(v, VISIT) for all e G.outIncidentdges(v) if getlabel(e) = UNXPLOR w opposite(v,e) if getlabel(w) = UNXPLOR setlabel(e, ISOVRY) S1S(G, w) else {e is a forward or cross edge} L.insertirst(v) irected Graphs S S Phase 2b Similar to onnected lgorithm S2bS(G R, v, sccnum) omponents Input graph G R and a start vertex v lgorithm S2bS_Sweep(G R,L) Output vertices of G R in the connected component of v labeled by Input dag G R, list L sccnum Output Labeling of vertices in setlabel(v, VISIT) G R by scc component number Label v with sccnum sccnum 1 for all e G.outIncidentdges(v) for all u G.vertices() if getlabel(e) = UNXPLOR setlabel(u, UNXPLOR) w opposite(v,e) for all e G.edges() if getlabel(w) = UNXPLOR setlabel(e, UNXPLOR) setlabel(e, ISOVRY) for all v L, {traverse L in order} S2bS(G, w) if getlabel(v) = UNXPLOR else S2bS(G, v, sccnum) {e is a forward or cross edge} sccnum++ O(n+m) time. irected Graphs S orrectness of S algorithm Lemma 1: In terms of vertices, S s of G are the same as the S s of G R. Lemma 2: or graph G, let be a forest generated by S_Sweep on G. Let S be a tree of. Then S contains one or more complete S s of G. (No partial S s). Lemma 3a: Let be the forest generated by S phase 2b, and S be a spanning tree in. Let x be the root of S, and v be a descendent of x. Then there is a path from v to x in G R. Lemma 3b: Let S be as in Lemma 3a. S combined with other edges in G R form a strongly connected subgraph of G R. irected Graphs S

11 readth-irst Search irected Graphs S Outline and Reading readth-first search ( 6.3.3) lgorithm xample Properties nalysis pplications S vs. S ( 6.3.3) omparison of applications omparison of edge labels irected Graphs S readth-irst Search readth-first search (S) is general graph traversal technique Visits all the vertices and edges with n vertices and m edges takes O(n + m ) time Like searching a binary tree level by level S can etermine whether G is connected ompute the connected components of G ompute a spanning forest of G ind and report a path with the minimum number of edges between two given vertices ind a simple cycle, if there is one irected Graphs S

12 xample unexplored vertex visited vertex unexplored edge discovery edge cross edge irected Graphs S xample (cont.) irected Graphs S xample (cont.) irected Graphs S

13 S lgorithm The algorithm uses a queue to keep track of vertices lgorithm S_Sweep(G) Input graph G Output labeling of the edges and the vertices of G for all u G.vertices() setlabel(u, UNXPLOR) for all e G.edges() setlabel(e, UNXPLOR) for all v G.vertices() if getlabel(v) = UNXPLOR S(G, v) lgorithm S(G, s) Q new empty queue Q.enqueue(s) setlabel(s, VISIT) while Q.ismpty() v Q.dequeue() for all e G.incidentdges(v) if getlabel(e) = UNXPLOR w opposite(v,e) if getlabel(w) = UNXPLOR setlabel(e, ISOVRY) setlabel(w, VISIT) Q.enqueue(w) else setlabel(e, ROSS) irected Graphs S Properties Notation G s : connected component of s L i : nodes at depth i in S tree. Property 1 S(G, s) visits all the vertices and edges of G s Property 2 The discovery edges labeled by S(G, s) form a spanning tree T s of G s ; T s called S tree Property 3 or each vertex v in L i The path of T s from s to v has i edges very path from s to v in G s has at least i edges irected Graphs S nalysis Setting/getting a vertex/edge label takes O(1) time ach vertex is labeled twice once as UNXPLOR once as VISIT ach edge is labeled twice once as UNXPLOR once as ISOVRY or ROSS ach vertex is inserted once into Q Inner loop of S runs in O(deg(v)) time S runs in O(n + m) time provided the graph is represented by the adjacency list structure Recall that Σ v deg(v) = 2m irected Graphs S 1.3 3

14 pplications an specialize the S traversal of a graph G to solve the following problems in O(n + m) time ompute the connected components of G ompute a spanning forest of G ind a simple cycle in G, or report that G is a forest Given two vertices of G, find a minimum length path in G (if it exists) irected Graphs S S vs. S pplications Spanning forest, connected components, paths, cycles Shortest paths Topological sort, iconnected components, S S S S S irected Graphs S S vs. S (cont.) On undirected graphs ack edge (v,w) ross edge (v,w) w is an ancestor of v in the tree of discovery edges w is in the same level as v or in the next level in the tree of discovery edges S S irected Graphs S

Digraphs ( 12.4) Directed Graphs. Digraph Application. Digraph Properties. A digraph is a graph whose edges are all directed.

Digraphs ( 12.4) Directed Graphs. Digraph Application. Digraph Properties. A digraph is a graph whose edges are all directed. igraphs ( 12.4) irected Graphs OR OS digraph is a graph whose edges are all directed Short for directed graph pplications one- way streets flights task scheduling irected Graphs 1 irected Graphs 2 igraph

More information

Breadth-First Search L 1 L Goodrich, Tamassia, Goldwasser Breadth-First Search 1

Breadth-First Search L 1 L Goodrich, Tamassia, Goldwasser Breadth-First Search 1 readth-irst Search 2013 Goodrich, Tamassia, Goldwasser readth-irst Search 1 readth-irst Search readth-first search (S) is a general technique for traversing a graph S traversal of a graph G Visits all

More information

Depth-First Search A B D E C

Depth-First Search A B D E C epth-first Search Outline and Reading efinitions (6.1) Subgraph onnectivity Spanning trees and forests epth-first search (6.3.1) lgorithm xample Properties nalysis pplications of FS (6.5) Path finding

More information

Directed Graphs BOS Goodrich, Tamassia Directed Graphs 1 ORD JFK SFO DFW LAX MIA

Directed Graphs BOS Goodrich, Tamassia Directed Graphs 1 ORD JFK SFO DFW LAX MIA Directed Graphs BOS ORD JFK SFO LAX DFW MIA 2010 Goodrich, Tamassia Directed Graphs 1 Digraphs A digraph is a graph whose edges are all directed Short for directed graph Applications one-way streets flights

More information

Graph ADT. Lecture18: Graph II. Adjacency Matrix. Representation of Graphs. Data Vertices and edges. Methods

Graph ADT. Lecture18: Graph II. Adjacency Matrix. Representation of Graphs. Data Vertices and edges. Methods Graph T S33: ata Structures (0) Lecture8: Graph II ohyung Han S, POSTH bhhan@postech.ac.kr ata Vertices and edges endvertices(e): an array of the two endvertices of e opposite(v,e): the vertex opposite

More information

Data Structures Lecture 14

Data Structures Lecture 14 Fall 2018 Fang Yu Software Security Lab. ept. Management Information Systems, National hengchi University ata Structures Lecture 14 Graphs efinition, Implementation and Traversal Graphs Formally speaking,

More information

Lecture 16: Directed Graphs

Lecture 16: Directed Graphs Lecture 16: Directed Graphs ORD JFK BOS SFO LAX DFW MIA Courtesy of Goodrich, Tamassia and Olga Veksler Instructor: Yuzhen Xie Outline Directed Graphs Properties Algorithms for Directed Graphs DFS and

More information

Lecture 14: Graph Representation, DFS and Applications

Lecture 14: Graph Representation, DFS and Applications Lecture 14: Graph Representation, FS and pplications SFO OR LX FW ourtesy to Goodrich, Tamassia and Olga Veksler Instructor: Yuzhen Xie Outline Graph Representation dge List djacency List djacency Matrix

More information

Applications of BFS and DFS

Applications of BFS and DFS pplications of S and S S all // : PM Some pplications of S and S S o find the shortest path from a vertex s to a vertex v in an unweighted graph o find the length of such a path o construct a S tree/forest

More information

CHAPTER 13 GRAPH ALGORITHMS ORD SFO LAX DFW

CHAPTER 13 GRAPH ALGORITHMS ORD SFO LAX DFW SFO ORD CHAPTER 13 GRAPH ALGORITHMS LAX DFW ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES

More information

Graph Terminology and Representations

Graph Terminology and Representations Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 Graph Terminology and Representations 1 Graphs A graph is a pair (V, E), where

More information

Graphs ORD SFO LAX DFW. Data structures and Algorithms

Graphs ORD SFO LAX DFW. Data structures and Algorithms SFO 143 ORD 337 1743 02 Graphs LAX 1233 DFW Data structures and Algorithms Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++ Goodrich, Tamassia and

More information

Depth-First Search and Template Patterns

Depth-First Search and Template Patterns Depth-First Search and Template Patterns A B D E C 1 Outline Template Patterns and Search Depth-first search Algorithm Example Properties Analysis Applications of DFS Path finding Cycle finding CS 4407,

More information

CISC 320 Introduction to Algorithms Fall Lecture 15 Depth First Search

CISC 320 Introduction to Algorithms Fall Lecture 15 Depth First Search IS 320 Introduction to lgorithms all 2014 Lecture 15 epth irst Search 1 Traversing raphs Systematic search of every edge and vertex of graph (directed or undirected) fficiency: each edge is visited no

More information

Analysis of Algorithms Prof. Karen Daniels

Analysis of Algorithms Prof. Karen Daniels UMass Lowell omputer Science 91.404 nalysis of lgorithms Prof. Karen aniels Spring, 2013 hapter 22: raph lgorithms & rief Introduction to Shortest Paths [Source: ormen et al. textbook except where noted]

More information

CS 225. April 16 Graph Traversal. Data Structures. Wade Fagen-Ulmschneider

CS 225. April 16 Graph Traversal. Data Structures. Wade Fagen-Ulmschneider CS 225 Data Structures April 16 Graph Traversal Wade Fagen-Ulmschneider Graph ADT Data: - Vertices - Edges - Some data structure maintaining the structure between vertices and edges. d V W f b e X Y g

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms CS 5311 Lecture 19 Topological Sort Junzhou Huang, Ph.D. Department of Computer Science and ngineering CS5311 Design and Analysis of Algorithms 1 Topological Sort Want

More information

Graphs ORD SFO LAX DFW. Graphs 1

Graphs ORD SFO LAX DFW. Graphs 1 Graphs ORD 1843 SFO 802 1743 337 1233 LAX DFW Graphs 1 Outline and Reading Graphs ( 12.1) Definition Applications Terminology Properties ADT Data structures for graphs ( 12.2) Edge list structure Adjacency

More information

Graph Algorithms Using Depth First Search

Graph Algorithms Using Depth First Search Graph Algorithms Using Depth First Search Analysis of Algorithms Week 8, Lecture 1 Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Graph Algorithms Using Depth

More information

Graphs ORD SFO LAX DFW Goodrich, Tamassia Graphs 1

Graphs ORD SFO LAX DFW Goodrich, Tamassia Graphs 1 Graphs SFO 33 143 ORD 02 LAX 1233 DFW 2004 Goodrich, Tamassia Graphs 1 What is a Graph? (in computer science, it s not a data plot) General structure for representing positions with an arbitrary connectivity

More information

CHAPTER 13 GRAPH ALGORITHMS

CHAPTER 13 GRAPH ALGORITHMS CHPTER 13 GRPH LGORITHMS SFO LX ORD DFW 1 CKNOWLEDGEMENT: THESE SLIDES RE DPTED FROM SLIDES PROVIDED WITH DT STRUCTURES ND LGORITHMS IN C++, GOODRICH, TMSSI ND MOUNT (WILEY 2004) ND SLIDES FROM JORY DENNY

More information

3.1 Basic Definitions and Applications

3.1 Basic Definitions and Applications Graphs hapter hapter Graphs. Basic efinitions and Applications Graph. G = (V, ) n V = nodes. n = edges between pairs of nodes. n aptures pairwise relationship between objects: Undirected graph represents

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms S 101, Winter 2018 esign and nalysis of lgorithms Lecture 3: onnected omponents lass URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ nd of Lecture 2: s, Topological Order irected cyclic raph.g., Vertices

More information

Advanced Data Structures and Algorithms

Advanced Data Structures and Algorithms dvanced ata Structures and lgorithms ssociate Professor r. Raed Ibraheem amed University of uman evelopment, College of Science and Technology Computer Science epartment 2015 2016 epartment of Computer

More information

Strongly Connected Components

Strongly Connected Components Strongly Connected Components Let G = (V, E) be a directed graph Write if there is a path from to in G Write if and is an equivalence relation: implies and implies s equivalence classes are called the

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 Chapter 3 - Graphs Undirected Graphs Undirected graph. G = (V, E) V = nodes. E = edges between pairs of nodes. Captures pairwise relationship between objects. Graph size parameters: n = V, m = E. Directed

More information

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Computer Science & Engineering 423/823 Design and Analysis of Algorithms s of s Computer Science & Engineering 423/823 Design and Analysis of Lecture 03 (Chapter 22) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 29 s of s s are abstract data types that are applicable

More information

CSE 331: Introduction to Algorithm Analysis and Design Graphs

CSE 331: Introduction to Algorithm Analysis and Design Graphs CSE 331: Introduction to Algorithm Analysis and Design Graphs 1 Graph Definitions Graph: A graph consists of a set of verticies V and a set of edges E such that: G = (V, E) V = {v 0, v 1,..., v n 1 } E

More information

Introduction to Graphs. common/notes/ppt/

Introduction to Graphs.   common/notes/ppt/ Introduction to Graphs http://people.cs.clemson.edu/~pargas/courses/cs212/ common/notes/ppt/ Introduction Graphs are a generalization of trees Nodes or verticies Edges or arcs Two kinds of graphs irected

More information

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1 Graph Algorithms Chapter 22 CPTR 430 Algorithms Graph Algorithms Why Study Graph Algorithms? Mathematical graphs seem to be relatively specialized and abstract Why spend so much time and effort on algorithms

More information

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11 Chapter 3 - Graphs Undirected Graphs Undirected graph. G = (V, E) V = nodes. E = edges between pairs of nodes. Captures pairwise relationship between objects. Graph size parameters: n = V, m = E. V = {

More information

Graph Representation

Graph Representation Graph Representation Adjacency list representation of G = (V, E) An array of V lists, one for each vertex in V Each list Adj[u] contains all the vertices v such that there is an edge between u and v Adj[u]

More information

CS2210 Data Structures and Algorithms

CS2210 Data Structures and Algorithms S1 ata Structures and Algorithms Lecture 1 : Shortest Paths A 4 1 5 5 3 4 Goodrich, Tamassia Outline Weighted Graphs Shortest Paths Algorithm (ijkstra s) Weighted Graphs ach edge has an associated numerical

More information

Strongly connected: A directed graph is strongly connected if every pair of vertices are reachable from each other.

Strongly connected: A directed graph is strongly connected if every pair of vertices are reachable from each other. Directed Graph In a directed graph, each edge (u, v) has a direction u v. Thus (u, v) (v, u). Directed graph is useful to model many practical problems (such as one-way road in traffic network, and asymmetric

More information

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch]

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch] Graph Algorithms Andreas Klappenecker [based on slides by Prof. Welch] 1 Directed Graphs Let V be a finite set and E a binary relation on V, that is, E VxV. Then the pair G=(V,E) is called a directed graph.

More information

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Computer Science & Engineering 423/823 Design and Analysis of Algorithms Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 04 Elementary Graph Algorithms (Chapter 22) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu Introduction

More information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees 0 OS SO LX PV OR 0 JK 0 WI 00 W MI 00 Goodrich, Tamassia Minimum Spanning Trees Minimum Spanning Trees Spanning subgraph Subgraph of a graph G containing all the vertices of G Spanning

More information

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 17. Depth-First Search. DFS (Initialize and Go) Last Time Depth-First Search

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 17. Depth-First Search. DFS (Initialize and Go) Last Time Depth-First Search Taking Stock IE170: Algorithms in Systems Engineering: Lecture 17 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University March 2, 2007 Last Time Depth-First Search This Time:

More information

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS Department of Computer Science University of Babylon LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS By Faculty of Science for Women( SCIW), University of Babylon, Iraq Samaher@uobabylon.edu.iq

More information

Directed Graphs (II) Hwansoo Han

Directed Graphs (II) Hwansoo Han Directed Graphs (II) Hwansoo Han Traversals of Directed Graphs To solve many problems dealing with digraphs, we need to visit vertexes and arcs in a systematic way Depth-first search (DFS) A generalization

More information

Graphs ORD SFO LAX DFW

Graphs ORD SFO LAX DFW Graphs SFO 337 1843 802 ORD LAX 1233 DFW Graphs A graph is a pair (V, E), where V is a set of odes, called vertices E is a collectio of pairs of vertices, called edges Vertices ad edges are positios ad

More information

Graphs. Part I: Basic algorithms. Laura Toma Algorithms (csci2200), Bowdoin College

Graphs. Part I: Basic algorithms. Laura Toma Algorithms (csci2200), Bowdoin College Laura Toma Algorithms (csci2200), Bowdoin College Undirected graphs Concepts: connectivity, connected components paths (undirected) cycles Basic problems, given undirected graph G: is G connected how many

More information

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY General definitions; Representations; Graph Traversals; Topological sort; Graphs definitions & representations Graph theory is a fundamental tool in sparse

More information

Reading. Graph Terminology. Graphs. What are graphs? Varieties. Motivation for Graphs. Reading. CSE 373 Data Structures. Graphs are composed of.

Reading. Graph Terminology. Graphs. What are graphs? Varieties. Motivation for Graphs. Reading. CSE 373 Data Structures. Graphs are composed of. Reading Graph Reading Goodrich and Tamassia, hapter 1 S 7 ata Structures What are graphs? Graphs Yes, this is a graph. Graphs are composed of Nodes (vertices) dges (arcs) node ut we are interested in a

More information

Practical Session No. 12 Graphs, BFS, DFS, Topological sort

Practical Session No. 12 Graphs, BFS, DFS, Topological sort Practical Session No. 12 Graphs, BFS, DFS, Topological sort Graphs and BFS Graph G = (V, E) Graph Representations (V G ) v1 v n V(G) = V - Set of all vertices in G E(G) = E - Set of all edges (u,v) in

More information

Graphs & Digraphs Tuesday, November 06, 2007

Graphs & Digraphs Tuesday, November 06, 2007 Graphs & Digraphs Tuesday, November 06, 2007 10:34 PM 16.1 Directed Graphs (digraphs) like a tree but w/ no root node & no guarantee of paths between nodes consists of: nodes/vertices - a set of elements

More information

Outline and Reading. Minimum Spanning Tree. Minimum Spanning Tree. Cycle Property. Minimum Spanning Trees ( 12.7)

Outline and Reading. Minimum Spanning Tree. Minimum Spanning Tree. Cycle Property. Minimum Spanning Trees ( 12.7) Outline and Reading Minimum Spanning Tree PV 1 1 1 1 JK 1 15 SO 11 1 LX 15 Minimum Spanning Trees ( 1.) efinitions crucial fact Prim-Jarnik s lgorithm ( 1..) Kruskal s lgorithm ( 1..1) 111 // :1 PM Minimum

More information

Lecture 9 Graph Traversal

Lecture 9 Graph Traversal Lecture 9 Graph Traversal Euiseong Seo (euiseong@skku.edu) SWE00: Principles in Programming Spring 0 Euiseong Seo (euiseong@skku.edu) Need for Graphs One of unifying themes of computer science Closely

More information

Suggested Study Strategy

Suggested Study Strategy Final Exam Thursday, 7 August 2014,19:00 22:00 Closed Book Will cover whole course, with emphasis on material after midterm (hash tables, binary search trees, sorting, graphs) Suggested Study Strategy

More information

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms Chapter 3 CSE 417: Algorithms and Computational Complexity Graphs Reading: 3.1-3.6 Winter 2012 Graphs and Graph Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

More information

Graph. Vertex. edge. Directed Graph. Undirected Graph

Graph. Vertex. edge. Directed Graph. Undirected Graph Module : Graphs Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS E-mail: natarajan.meghanathan@jsums.edu Graph Graph is a data structure that is a collection

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 4 Graphs Definitions Traversals Adam Smith 9/8/10 Exercise How can you simulate an array with two unbounded stacks and a small amount of memory? (Hint: think of a

More information

Outline. Graphs. Divide and Conquer.

Outline. Graphs. Divide and Conquer. GRAPHS COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges books. Outline Graphs.

More information

Graph: representation and traversal

Graph: representation and traversal Graph: representation and traversal CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang! Acknowledgement The set of slides have use materials from the following resources Slides for textbook

More information

ECE 242 Data Structures and Algorithms. Graphs II. Lecture 27. Prof.

ECE 242 Data Structures and Algorithms.  Graphs II. Lecture 27. Prof. 242 ata Structures and lgorithms http://www.ecs.umass.edu/~polizzi/teaching/242/ Graphs II Lecture 27 Prof. ric Polizzi Summary Previous Lecture omposed of vertices (nodes) and edges vertex or node edges

More information

Week 5. 1 Analysing BFS. 2 Depth-first search. 3 Analysing DFS. 4 Dags and topological sorting. 5 Detecting cycles. CS 270 Algorithms.

Week 5. 1 Analysing BFS. 2 Depth-first search. 3 Analysing DFS. 4 Dags and topological sorting. 5 Detecting cycles. CS 270 Algorithms. 1 2 Week 5 3 4 5 General remarks We finish, by analysing it. Then we consider the second main graph- algorithm, depth-first (). And we consider one application of, of graphs. Reading from CLRS for week

More information

Applications of BDF and DFS

Applications of BDF and DFS January 14, 2016 1 Deciding whether a graph is bipartite using BFS. 2 Finding connected components of a graph (both BFS and DFS) works. 3 Deciding whether a digraph is strongly connected. 4 Finding cut

More information

Announcements. HW3 is graded. Average is 81%

Announcements. HW3 is graded. Average is 81% CSC263 Week 9 Announcements HW3 is graded. Average is 81% Announcements Problem Set 4 is due this Tuesday! Due Tuesday (Nov 17) Recap The Graph ADT definition and data structures BFS gives us single-source

More information

Inf 2B: Graphs II - Applications of DFS

Inf 2B: Graphs II - Applications of DFS Inf 2B: Graphs II - Applications of DFS Kyriakos Kalorkoti School of Informatics University of Edinburgh Reminder: Recursive DFS Algorithm dfs(g) 1. Initialise Boolean array visited by setting all entries

More information

CHAPTER 14 GRAPH ALGORITHMS ORD SFO LAX DFW

CHAPTER 14 GRAPH ALGORITHMS ORD SFO LAX DFW SO OR HPTR 1 GRPH LGORITHMS LX W KNOWLGMNT: THS SLIS R PT ROM SLIS PROVI WITH T STRUTURS N LGORITHMS IN JV, GOORIH, TMSSI N GOLWSSR (WILY 16) 6 OS MINIMUM SPNNING TRS SO 16 PV OR 1 1 16 61 JK 1 1 11 WI

More information

Computational Geometry

Computational Geometry Orthogonal Range Searching omputational Geometry hapter 5 Range Searching Problem: Given a set of n points in R d, preprocess them such that reporting or counting the k points inside a d-dimensional axis-parallel

More information

Graph Traversals. CS200 - Graphs 1

Graph Traversals. CS200 - Graphs 1 Graph Traversals CS200 - Graphs 1 Tree traversal reminder A Pre order A B D G H C E F I B C In order G D H B A E C F I D E F Post order G H D B E I F C A G H I Level order A B C D E F G H I Connected Components

More information

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

Graphs V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)} Graphs and Trees 1 Graphs (simple) graph G = (V, ) consists of V, a nonempty set of vertices and, a set of unordered pairs of distinct vertices called edges. xamples V={,,,,} ={ (,),(,),(,), (,),(,),(,)}

More information

Graph Algorithms. Definition

Graph Algorithms. Definition Graph Algorithms Many problems in CS can be modeled as graph problems. Algorithms for solving graph problems are fundamental to the field of algorithm design. Definition A graph G = (V, E) consists of

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 5 Graphs Applications of DFS Topological sort Strongly connected components Sofya Raskhodnikova S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith,

More information

CS 361 Data Structures & Algs Lecture 15. Prof. Tom Hayes University of New Mexico

CS 361 Data Structures & Algs Lecture 15. Prof. Tom Hayes University of New Mexico CS 361 Data Structures & Algs Lecture 15 Prof. Tom Hayes University of New Mexico 10-12-2010 1 Last Time Identifying BFS vs. DFS trees Can they be the same? Problems 3.6, 3.9, 3.2 details left as homework.

More information

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms Chapter 9 Graph Algorithms 2 Introduction graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 3 Definitions an undirected graph G = (V, E)

More information

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions Introduction Chapter 9 Graph Algorithms graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 2 Definitions an undirected graph G = (V, E) is

More information

TCOM 501: Networking Theory & Fundamentals. Lecture 11 April 16, 2003 Prof. Yannis A. Korilis

TCOM 501: Networking Theory & Fundamentals. Lecture 11 April 16, 2003 Prof. Yannis A. Korilis TOM 50: Networking Theory & undamentals Lecture pril 6, 2003 Prof. Yannis. Korilis 2 Topics Routing in ata Network Graph Representation of a Network Undirected Graphs Spanning Trees and Minimum Weight

More information

DEPTH-FIRST SEARCH A B C D E F G H I J K L M N O P. Graph Traversals. Depth-First Search

DEPTH-FIRST SEARCH A B C D E F G H I J K L M N O P. Graph Traversals. Depth-First Search PTH-IRST SRH raph Traversals epth-irst Search H I J K L M N O P epth-irst Search 1 xploring a Labyrinth Without etting Lost depth-first search (S) in an undirected graph is like wandering in a labyrinth

More information

CS 5114: Theory of Algorithms. Graph Algorithms. A Tree Proof. Graph Traversals. Clifford A. Shaffer. Spring 2014

CS 5114: Theory of Algorithms. Graph Algorithms. A Tree Proof. Graph Traversals. Clifford A. Shaffer. Spring 2014 epartment of omputer Science Virginia Tech lacksburg, Virginia opyright c 04 by lifford. Shaffer : Theory of lgorithms Title page : Theory of lgorithms lifford. Shaffer Spring 04 lifford. Shaffer epartment

More information

Depth-first search in undirected graphs What parts of the graph are reachable from a given vertex?

Depth-first search in undirected graphs What parts of the graph are reachable from a given vertex? Why graphs? Chapter 3. Decompositions of graphs Awiderangeofproblemscanbeexpressedwithclarityandprecisionin the concise pictorial language of graphs. Graph coloring. Graph connectivity and reachability.

More information

Breadth First Search. Graph Traversal. CSE 2011 Winter Application examples. Two common graph traversal algorithms

Breadth First Search. Graph Traversal. CSE 2011 Winter Application examples. Two common graph traversal algorithms Breadth irst Search CSE Winter Graph raversal Application examples Given a graph representation and a vertex s in the graph ind all paths from s to the other vertices wo common graph traversal algorithms

More information

CS 270 Algorithms. Oliver Kullmann. Analysing BFS. Depth-first search. Analysing DFS. Dags and topological sorting.

CS 270 Algorithms. Oliver Kullmann. Analysing BFS. Depth-first search. Analysing DFS. Dags and topological sorting. General remarks Week 5 2 We finish, by analysing it. Then we consider the second main graph- algorithm, depth-first (). And we consider one application of, of graphs. Reading from CLRS for week 5 Chapter

More information

CS4800: Algorithms & Data Jonathan Ullman

CS4800: Algorithms & Data Jonathan Ullman CS4800: Algorithms & Data Jonathan Ullman Lecture 12: Graph Search: BFS Applications, DFS Feb 20, 2018 BFS Review BFS Algorithm: Input: source node! " # =! " % = all neighbors of " # " & = all neighbors

More information

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

Algorithms (VII) Yijia Chen Shanghai Jiaotong University Algorithms (VII) Yijia Chen Shanghai Jiaotong University Review of the Previous Lecture Depth-first search in undirected graphs Exploring graphs explore(g, v) Input: G = (V, E) is a graph; v V Output:

More information

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

Algorithms (VII) Yijia Chen Shanghai Jiaotong University Algorithms (VII) Yijia Chen Shanghai Jiaotong University Review of the Previous Lecture Depth-first search in undirected graphs Exploring graphs explore(g, v) Input: G = (V, E) is a graph; v V Output:

More information

Graphs ADTs and Implementations

Graphs ADTs and Implementations Graphs ADTs and Implementations SFO 337 1843 802 ORD LAX 1233 DFW - 1 - Applications of Graphs Ø Electronic circuits cslab1a cslab1b q Printed circuit board math.brown.edu q Integrated circuit Ø Transportation

More information

CS 491 CAP Introduction to Graphs and Search

CS 491 CAP Introduction to Graphs and Search CS 491 CAP Introduction to Graphs and Search Jingbo Shang University of Illinois at Urbana-Champaign Sep 9, 2016 Outline Graphs Adjacency Matrix vs. Adjacency List Special Graphs Depth-first and Breadth-first

More information

DFS & STRONGLY CONNECTED COMPONENTS

DFS & STRONGLY CONNECTED COMPONENTS DFS & STRONGLY CONNECTED COMPONENTS CS 4407 Search Tree Breadth-First Search (BFS) Depth-First Search (DFS) Depth-First Search (DFS) u d[u]: when u is discovered f[u]: when searching adj of u is finished

More information

Cut vertices, Cut Edges and Biconnected components. MTL776 Graph algorithms

Cut vertices, Cut Edges and Biconnected components. MTL776 Graph algorithms Cut vertices, Cut Edges and Biconnected components MTL776 Graph algorithms Articulation points, Bridges, Biconnected Components Let G = (V;E) be a connected, undirected graph. An articulation point of

More information

Data Structures. Elementary Graph Algorithms BFS, DFS & Topological Sort

Data Structures. Elementary Graph Algorithms BFS, DFS & Topological Sort Data Structures Elementary Graph Algorithms BFS, DFS & Topological Sort 1 Graphs A graph, G = (V, E), consists of two sets: V is a finite non-empty set of vertices. E is a set of pairs of vertices, called

More information

Graph Representations and Traversal

Graph Representations and Traversal COMPSCI 330: Design and Analysis of Algorithms 02/08/2017-02/20/2017 Graph Representations and Traversal Lecturer: Debmalya Panigrahi Scribe: Tianqi Song, Fred Zhang, Tianyu Wang 1 Overview This lecture

More information

CHAPTER 14 GRAPH ALGORITHMS ORD SFO LAX DFW

CHAPTER 14 GRAPH ALGORITHMS ORD SFO LAX DFW SFO ORD CHAPTER 14 GRAPH ALGORITHMS LAX DFW ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016) GRAPH

More information

Graphs. A graph is a data structure consisting of nodes (or vertices) and edges. An edge is a connection between two nodes

Graphs. A graph is a data structure consisting of nodes (or vertices) and edges. An edge is a connection between two nodes Graphs Graphs A graph is a data structure consisting of nodes (or vertices) and edges An edge is a connection between two nodes A D B E C Nodes: A, B, C, D, E Edges: (A, B), (A, D), (D, E), (E, C) Nodes

More information

CS781 Lecture 2 January 13, Graph Traversals, Search, and Ordering

CS781 Lecture 2 January 13, Graph Traversals, Search, and Ordering CS781 Lecture 2 January 13, 2010 Graph Traversals, Search, and Ordering Review of Lecture 1 Notions of Algorithm Scalability Worst-Case and Average-Case Analysis Asymptotic Growth Rates: Big-Oh Prototypical

More information

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10 CS 220: Discrete Structures and their Applications graphs zybooks chapter 10 directed graphs A collection of vertices and directed edges What can this represent? undirected graphs A collection of vertices

More information

12/5/17. trees. CS 220: Discrete Structures and their Applications. Trees Chapter 11 in zybooks. rooted trees. rooted trees

12/5/17. trees. CS 220: Discrete Structures and their Applications. Trees Chapter 11 in zybooks. rooted trees. rooted trees trees CS 220: Discrete Structures and their Applications A tree is an undirected graph that is connected and has no cycles. Trees Chapter 11 in zybooks rooted trees Rooted trees. Given a tree T, choose

More information

Finding Strongly Connected Components

Finding Strongly Connected Components Yufei Tao ITEE University of Queensland We just can t get enough of the beautiful algorithm of DFS! In this lecture, we will use it to solve a problem finding strongly connected components that seems to

More information

L10 Graphs. Alice E. Fischer. April Alice E. Fischer L10 Graphs... 1/37 April / 37

L10 Graphs. Alice E. Fischer. April Alice E. Fischer L10 Graphs... 1/37 April / 37 L10 Graphs lice. Fischer pril 2016 lice. Fischer L10 Graphs... 1/37 pril 2016 1 / 37 Outline 1 Graphs efinition Graph pplications Graph Representations 2 Graph Implementation 3 Graph lgorithms Sorting

More information

CSE 421 DFS / Topological Ordering

CSE 421 DFS / Topological Ordering CSE 421 DFS / Topological Ordering Shayan Oveis Gharan 1 Depth First Search Follow the first path you find as far as you can go; back up to last unexplored edge when you reach a dead end, then go as far

More information

Graph representation

Graph representation Graph Algorithms 1 Graph representation Given graph G = (V, E). May be either directed or undirected. Two common ways to represent for algorithms: 1. Adjacency lists. 2. Adjacency matrix. When expressing

More information

Data Struct. & Prob. Solving, M.C.Q. BANK, FOR UNIT 3, SECOND YEAR COMP. ENGG. SEM 1, 2012 PATTERN, U.O.P.

Data Struct. & Prob. Solving, M.C.Q. BANK, FOR UNIT 3, SECOND YEAR COMP. ENGG. SEM 1, 2012 PATTERN, U.O.P. UNIT distribution for +1+1 + 1 + + = 11 (Only 1 will be asked for marks, s will be asked for 1 & s asked for marks ) Syllabus for Graphs Programmers perspective of graphs, Graph operations, storage structure,

More information

Plan. CMPSCI 311: Introduction to Algorithms. Recall. Adjacency List Representation. DFS Descriptions. BFS Description

Plan. CMPSCI 311: Introduction to Algorithms. Recall. Adjacency List Representation. DFS Descriptions. BFS Description Plan CMPSCI 311: Introduction to Algorithms Akshay Krishnamurthy and Andrew McGregor University of Massachusetts Review: Breadth First Search Depth First Search Traversal Implementation and Running Time

More information

Chapter 22. Elementary Graph Algorithms

Chapter 22. Elementary Graph Algorithms Graph Algorithms - Spring 2011 Set 7. Lecturer: Huilan Chang Reference: (1) Cormen, Leiserson, Rivest, and Stein, Introduction to Algorithms, 2nd Edition, The MIT Press. (2) Lecture notes from C. Y. Chen

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 7 Greedy Graph Algorithms Topological sort Shortest paths Adam Smith The (Algorithm) Design Process 1. Work out the answer for some examples. Look for a general principle

More information

Graph Theory. Many problems are mapped to graphs. Problems. traffic VLSI circuits social network communication networks web pages relationship

Graph Theory. Many problems are mapped to graphs. Problems. traffic VLSI circuits social network communication networks web pages relationship Graph Graph Usage I want to visit all the known famous places starting from Seoul ending in Seoul Knowledge: distances, costs Find the optimal(distance or cost) path Graph Theory Many problems are mapped

More information

Basic Graph Definitions

Basic Graph Definitions CMSC 341 Graphs Basic Graph Definitions A graph G = (V,E) consists of a finite set of vertices, V, and a finite set of edges, E. Each edge is a pair (v,w) where v, w V. V and E are sets, so each vertex

More information

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Computer Science & Engineering 423/823 Design and Analysis of Algorithms s of s Computer Science & Engineering 423/823 Design and Analysis of Lecture 03 (Chapter 22) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 29 Spring 2010 s of s s are abstract data types that

More information

INF2220: algorithms and data structures Series 7

INF2220: algorithms and data structures Series 7 Universitetet i Oslo nstitutt for nformatikk. Yu,. arabeg uiologo NF2220: algorithms and data structures Series 7 Topic ore on graphs: FS, iconnectivity, and strongly connected components (Exercises with

More information