3.1 Basic Definitions and Applications

Size: px
Start display at page:

Download "3.1 Basic Definitions and Applications"

Transcription

1 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 symmetric relation irected graph represents general binary relation n Graph size parameters: n = V, m =. n Simple: no loops and no multiple edges V = {,,,,,,, } = { -, -, -, -, -, -, -, -, -, - } n = m = World Wide Web cological Food Web Some Graph Applications Web graph. Food web graph. n Node: web page. n Node = species. Graph Nodes dges n dge: hyperlink from one page to another. n dge = from prey to predator. transportation street intersections highways communication computers fiber optic cables World Wide Web web pages hyperlinks cnn.com social people relationships food web species predator-prey software systems functions function calls netscape.com novell.com cnnsi.com timewarner.com scheduling tasks precedence constraints circuits gates wires hbo.com sorpranos.com Reference:

2 Graph Representation: Adjacency Matrix Graph Representation: Adjacency List Paths and onnectivity Adjacency matrix. n-by-n matrix with A uv = if (u, v) is an edge. n Two s of each edge for undirected graph. n Space proportional to n. n hecking if (u, v) is an edge takes () time. n Identifying all edges takes (n ) time. Adjacency list. Node indexed array of lists. n Two representations of each edge for undirected graphs. n Space proportional to m + n. degree = number of neighbors of u n hecking if (u, v) is an edge takes O(deg(u)) time. n Identifying all edges takes (m + n) time. ef. A path in a graph G = (V, ) is a sequence P of nodes v, v,, v k-, v k with the property that each consecutive pair (v i, v i+ ) is an edge in. ef. A path is simple if all nodes are distinct. ef. An undirected graph is connected if for every pair of nodes u and v, there is a path from u to v. ef. A directed graph is strongly connected if for every pair of nodes u and v, there is a path from u to v. ycles Trees Rooted Trees ef. A cycle is a path v, v,, v k-, v k in which v = v k, k >, and the first k- nodes are all distinct. ef. An undirected graph is a tree if it is connected and does not contain a cycle. Theorem. Let G be an undirected graph on n nodes. Any two of the following statements imply the third. n G is connected. n G does not contain a cycle. n G has n- edges. Rooted tree. A directed graph where its underlying undirected graph is a tree and there is a node r called root and each edge points away from r. Importance. Models hierarchical structure. root r parent of v v cycle = child of v a tree the same tree, rooted at

3 onnectivity Breadth First Search. Graph Traversal s-t connectivity problem. Given two node s and t, is there a path between s and t? BFS intuition. xplore outward from s in all possible directions, adding nodes one "layer" at a time. s-t shortest path problem. Given two node s and t, what is the length of the shortest path between s and t? Applications. n Maze traversal. n Fewest number of hops in a communication network. BFS algorithm. n L = { s }. s L L L n- n L = all neighbors of L. n L = all nodes that do not belong to L or L, and that have an edge to a node in L. n L i+ = all nodes that do not belong to an earlier layer, and that have an edge to a node in L i. Theorem. For each i, L i consists of all nodes at distance exactly i from s. There is a path from s to t iff t appears in some layer. Breadth First Search Breadth First Search: Analysis onnected omponent Property. Let T be a BFS tree of G = (V, ), and let (x, y) be an edge of G. Then the level of x and y differ by at most. Theorem. The above implementation of BFS runs in O(m + n) time if the graph is given by its adjacency representation. onnected component. Find all nodes reachable from s. Pf. n Runs in O(m + n) time: when we consider node u, there are deg(u) incident edges (u, v) total time processing edges is u V deg(u) = m each edge (u, v) is counted exactly twice in sum: once in deg(u) and once in deg(v) L L onnected component containing node = {,,,,,,, }. L L

4 onnected omponent Breadth-First Search xample Breadth-First Search xample onnected component. Find all nodes reachable from s. s R u it's safe to add v v Theorem. Upon termination, R is the connected component containing s. n BFS = explore in order of distance from s. Start search at vertex. Visit/mark/label start vertex and put in a FIFO queue. Breadth-First Search xample Breadth-First Search xample Breadth-First Search xample Remove from Q; visit adjacent unvisited vertices; Remove from Q; visit adjacent unvisited vertices; Remove from Q; visit adjacent unvisited vertices;

5 Breadth-First Search xample Breadth-First Search xample Breadth-First Search xample Remove from Q; visit adjacent unvisited vertices; Remove from Q; visit adjacent unvisited vertices; Remove from Q; visit adjacent unvisited vertices; Breadth-First Search xample Breadth-First Search xample Breadth-First Search xample Remove from Q; visit adjacent unvisited vertices; Remove from Q; visit adjacent unvisited vertices; Remove from Q; visit adjacent unvisited vertices;

6 Breadth-First Search xample Breadth-First Search xample Breadth-First Search xample Remove from Q; visit adjacent unvisited vertices; Remove from Q; visit adjacent unvisited vertices; Remove from Q; visit adjacent unvisited vertices; Breadth-First Search xample Breadth-First Search xample Breadth-First Search xample Remove from Q; visit adjacent unvisited vertices; Remove from Q; visit adjacent unvisited vertices; Remove from Q; visit adjacent unvisited vertices;

7 Breadth-First Search xample Breadth-First Search xample Breadth-First Search xample Remove from Q; visit adjacent unvisited vertices; Remove from Q; visit adjacent unvisited vertices; Queue is empty. Search terminates. Time omplexity onnected omponents Spanning Tree ach visited vertex is put on (and so removed from) the queue exactly once. When a vertex is removed from the queue, we examine its adjacent vertices. O(n) if adjacency matrix used O(vertex degree) if adjacency lists used Total time O(kn), where k is number of vertices in the component that is searched (adjacency matrix) O(k+m), where m is the number of edges in the component (adjacency list). Start a breadth-first search at any as yet unvisited vertex of the graph. Newly visited vertices (plus edges between them) define a component. Repeat until all vertices are visited. O(n ) when adjacency matrix used O(n+m) when adjacency lists used (m is number of edges) A subgraph of a connected graph that contains every vertex and is a tree. Breadth-first search from vertex. Breadth-first spanning tree.

8 Spanning Tree epth-first Search for Undirected Graph epth-first Search xample Start a breadth-first search at any vertex of the graph. If graph is connected, the n- edges used to get to unvisited vertices define a spanning tree (breadth-first spanning tree). All visited vertices have the shortest steps to the start vertex in this spanning tree. Time depthfirstsearch(v) { Mark vertex v as reached. for (each vertex u adjacenct from v) if (unreached(u)) depthfirstsearch(u); // (v, u) is a tree edge. // else either (u, v) is a true edge or (v, u) is a back edge. } O(n ) when adjacency matrix used O(n+m) when adjacency lists used (m is number of edges) Start search at vertex. Label vertex and do a depth first search from either or. Suppose that vertex is selected. epth-first Search xample epth-first Search xample epth-first Search xample Label vertex and do a depth first search from either,, or. Suppose that vertex is selected. Label vertex and do a depth first search from either,, or. Suppose that vertex is selected. Label vertex and do a depth first search from either or. Suppose that vertex is selected.

9 epth-first Search xample epth-first Search xample epth-first Search xample Label vertex and return to vertex. From vertex do a dfs(). Label vertex and do a depth first search from either or. Suppose that vertex is selected. Label vertex and return to. From vertex do a dfs(). epth-first Search xample epth-first Search xample epth-first Search xample Label vertex and return to. Return to. Return to. o a dfs().

10 epth-first Search xample epth-first Search xample epth-first Search xample Label and return to. Return to. Return to. Return to the invoking method. epth-first Search Properties Bipartite Graphs Same complexity as BFS. Same properties with respect to path finding, connected components, and spanning trees. dges used to reach unlabeled vertices define a depth-first spanning tree when the graph is connected. There are problems for which BFS is better than FS and vice versa.. Testing Bipartiteness ef. An undirected graph G = (V, ) is bipartite if the nodes can be colored red or blue such that every edge has one red and one blue end. Applications. n Stable marriage: men = red, women = blue. n Scheduling: machines = red, jobs = blue. All edges are classified as either tree edges or back edges. Theorem: For any back edge (v, u), (u, v) lies in a cycle. a bipartite graph

11 v v v v v Testing Bipartiteness An Obstruction to Bipartiteness Obstruction to Bipartiteness Testing bipartiteness. Given a graph G, is it bipartite? n Many graph problems become: easier if the underlying graph is bipartite (matching) tractable if the underlying graph is bipartite (independent set) n Before attempting to design an algorithm, we need to understand structure of bipartite graphs. Lemma. If a graph G is bipartite, it cannot contain an odd length cycle. Pf. Not possible to -color the odd cycle, let alone G. orollary. A graph G is bipartite iff it contain no odd length cycle. v -cycle v v v v v v v v bipartite (-colorable) not bipartite (not -colorable) bipartite (-colorable) not bipartite (not -colorable) a bipartite graph G another drawing of G Testing Bipartiteness using epth-first Search Graph Search depthfirstsearch(v) { Mark vertex v as reached. for (each vertex u adjacent from v) if (unreached(u)) depthfirstsearch(u); // (v, u) is a tree edge. // else either (u, v) is a tree edge or (v, u) is a back edge. } boolean bipartitefs(v, color) { Mark vertex v as color color = oppositeolor(color) // white = oppositeolor(black), for (each vertex u adjacent from v) if (unmarked(u)) // (v, u) is a tree edge. if (! bipartitefs(u, color)) return false; else if (color(v) == color(u)) // (v, u) is a back edge. return false return true }. onnectivity in irected Graphs irected reachability. Given a node s, find all nodes reachable from s. irected s-t shortest path problem. Given two node s and t, what is the length of the shortest path between s and t? Graph search. BFS extends naturally to directed graphs. Web crawler. Start from web page s. Find all web pages linked from s, either directly or indirectly.

12 Strong onnectivity ef. Nodes u and v are mutually reachable if there is a path from u to v and also a path from v to u. ef. A graph is strongly connected if every pair of nodes is mutually reachable. Lemma. Let s be any node. G is strongly connected iff every node is reachable from s, and s is reachable from every node. Strong onnectivity: Algorithm Theorem. an determine if G is strongly connected in O(m + n) time. Pf. n Pick any node s. n Run FS from s in G. reverse orientation of every edge in G n Run FS from s in G rev. n Return true iff all nodes reached in both FS executions. n orrectness follows immediately from previous lemma. Strongly onnected omponents Any directed graph can be partitioned into a unique set of strong components. Pf. Follows from definition. Pf. Path from u to v: concatenate u-s path with s-v path. Path from v to u: concatenate v-s path with s-u path. ok if paths overlap s u strongly connected not strongly connected v Strongly onnected omponents (continued) Strongly onnected omponents (example) Strongly onnected omponents (continued) The algorithm for finding the strong components of a directed graph G uses the transpose of the graph. n The transpose G T has the same set of vertices V as graph G but a new edge set consisting of the edges of G but with the opposite direction.. xecute the depth-first search dfs() for the graph G which creates the list dfslist consisting of the vertices in G in the reverse order of their finishing times.. Generate the transpose graph G T.. Using the order of vertices in dfslist, make repeated calls to dfs() for vertices in G T. The list returned by each call is a strongly connected component of G. dfslist: [A, B,,,, G, F] Using the order of vertices in dfslist, make successive calls to dfs() for graph G T Vertex A: dfs(a) returns the list [A,, B] of vertices reachable from A in G T. Vertex : The next unvisited vertex in dfslist is. alling dfs() returns the list []. Vertex : The next unvisited vertex in dfslist is ; dfs() returns the list [, F, G] whose elements form the last strongly connected component.

13 Running Time of strongomponents() Recall that the depth-first search has running time O(V+), and the computation for G T is also O(V+). It follows that the running time for the algorithm to compute the strong components is O(V+).. AGs and Topological Ordering irected Acyclic Graphs ef. An AG is a directed graph that contains no directed cycles. x. Precedence constraints: edge (v i, v j ) means v i must precede v j. ef. A topological order of a directed graph G = (V, ) is an ordering of its nodes as v, v,, v n so that for every edge (v i, v j ) we have i < j. v v v v v v v v v v v v v v a AG a topological ordering Precedence onstraints irected Acyclic Graphs irected Acyclic Graphs Precedence constraints. dge (v i, v j ) means task v i must occur before v j. Lemma. If G has a topological order, then G is a AG. Lemma. If G has a topological order, then G is a AG. Applications. n ourse prerequisite graph: course v i must be taken before v j. n ompilation: module v i must be compiled before v j. n Pipeline of computing jobs: output of job v i needed to determine input of job v j. Topological Order: A listing of all nodes v, v,, v n, such that all edge (v i, v j ) has the property that i < j. Applications. n A study plan with course prerequisite graph. n A schedule of modules for compilation. Pf. (by contradiction) n Suppose that G has a topological order v,, v n and that G also has a directed cycle. Let's see what happens. n Let v i be the lowest-indexed node in, and let v j be the node just before v i ; thus (v j, v i ) is an edge. n By our choice of i, we have i < j. n On the other hand, since (v j, v i ) is an edge and v,, v n is a topological order, we must have j < i, a contradiction. the directed cycle v v i v j v n Q. oes every AG have a topological ordering? Q. If so, how do we compute one? the supposed topological order: v,, v n

14 irected Acyclic Graphs irected Acyclic Graphs Graph Algorithms: Topological Sort Lemma. If G is a AG, then G has a node with no incoming edges. Pf. (by contradiction) n Suppose that G is a AG and every node has at least one incoming edge. Let's see what happens. n Pick any node v, and begin following edges backward from v. Since v has at least one incoming edge (u, v) we can walk backward to u. n Then, since u has at least one incoming edge (x, u), we can walk backward to x. n Repeat until we visit a node, say w, twice. n Let denote the sequence of nodes encountered between successive visits to w. is a cycle. w x u v Lemma. If G is a AG, then G has a topological ordering. Pf. (by induction on n) n Base case: true if n =. n Given AG on n > nodes, find a node v with no incoming edges. n G - { v } is a AG, since deleting v cannot create cycles. n By inductive hypothesis, G - { v } has a topological ordering. n Place v first in topological ordering; then append nodes of G - { v } n in topological order. This is valid since v has no incoming edges. AG v A The topological sorting algorithm: Key idea: initialize and maintain a queue (or stack) holding pointers to the vertices with predecessors B F A B F B Graph Algorithms: Topological Sort Graph Algorithms: Topological Sort Graph Algorithms: Topological Sort The topological sorting algorithm: As each vertex is removed, update the predecessor counts, and for any vertex whose count has become zero, put it in the queue. The topological sorting algorithm: As each vertex is removed, update the predecessor counts, and for any vertex whose count has become zero, put it in the queue. The topological sorting algorithm: As each vertex is removed, update the predecessor counts, and for any vertex whose count has become zero, put it in the queue. A B F A B F B B F A B F No scan is required, so O(). Output: A B A B F Output: A F

15 Graph Algorithms: Topological Sort Graph Algorithms: Topological Sort Graph Algorithms: Topological Sort The topological sorting algorithm: As each vertex is removed, update the predecessor counts, and for any vertex whose count has become zero, put it in the queue. The topological sorting algorithm: As each vertex is removed, update the predecessor counts, and for any vertex whose count has become zero, put it in the queue. The topological sorting algorithm: As each vertex is removed, update the predecessor counts, and for any vertex whose count has become zero, put it in the queue. A B F Output: A F B A B F Output: A F B A B F Output: A F B Topological Sorting Algorithm: Running Time Theorem. Algorithm finds a topological order in O(m + n) time. Pf. n Maintain the following information: count[w] = remaining number of incoming edges S = set of remaining nodes with no incoming edges n Initialization: O(m + n) via single scan through graph. n Update: to delete v remove v from S decrement count[w] for all edges from v to w, and add w to S if c count[w] hits this is O() per edge

3.1 Basic Definitions and Applications. Chapter 3. Graphs. Undirected Graphs. Some Graph Applications

3.1 Basic Definitions and Applications. Chapter 3. Graphs. Undirected Graphs. Some Graph Applications Chapter 3 31 Basic Definitions and Applications Graphs Slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley All rights reserved 1 Undirected Graphs Some Graph Applications Undirected graph G = (V,

More information

Chapter 3. Graphs. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 3. Graphs. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 3 Graphs Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 3.1 Basic Definitions and Applications Undirected Graphs Undirected graph. G = (V, E) V = nodes. E

More information

3.1 Basic Definitions and Applications

3.1 Basic Definitions and Applications Chapter 3 Graphs Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 3.1 Basic Definitions and Applications Undirected Graphs Undirected graph. G = (V, E) V = nodes. E

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 Linear Time: O(n) CS 580: Algorithm Design and Analysis 2.4 A Survey of Common Running Times Merge. Combine two sorted lists A = a 1,a 2,,a n with B = b 1,b 2,,b n into sorted whole. Jeremiah Blocki Purdue

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

Chapter 3. Graphs CLRS Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 3. Graphs CLRS Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 3 Graphs CLRS 12-13 Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 25 3.4 Testing Bipartiteness Bipartite Graphs Def. An undirected graph G = (V, E) is bipartite

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

Chapter 3. Graphs CLRS Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 3. Graphs CLRS Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 3 Graphs CLRS 12-13 Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 3.1 Basic Definitions and Applications Undirected Graphs Undirected graph. G = (V, E) V

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

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

Algorithms: Lecture 10. Chalmers University of Technology

Algorithms: Lecture 10. Chalmers University of Technology Algorithms: Lecture 10 Chalmers University of Technology Today s Topics Basic Definitions Path, Cycle, Tree, Connectivity, etc. Graph Traversal Depth First Search Breadth First Search Testing Bipartatiness

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

3. GRAPHS. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley Copyright 2013 Kevin Wayne. Last updated on Sep 8, :19 AM

3. GRAPHS. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley Copyright 2013 Kevin Wayne. Last updated on Sep 8, :19 AM 3. GRAPHS basic definitions and applications graph connectivity and graph traversal testing bipartiteness connectivity in directed graphs DAGs and topological ordering Lecture slides by Kevin Wayne Copyright

More information

Graph Algorithms. Imran Rashid. Jan 16, University of Washington

Graph Algorithms. Imran Rashid. Jan 16, University of Washington Graph Algorithms Imran Rashid University of Washington Jan 16, 2008 1 / 26 Lecture Outline 1 BFS Bipartite Graphs 2 DAGs & Topological Ordering 3 DFS 2 / 26 Lecture Outline 1 BFS Bipartite Graphs 2 DAGs

More information

Graph Search Methods. Graph Search Methods

Graph Search Methods. Graph Search Methods Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. 0 Graph Search Methods A search method starts at a given vertex v and visits/labels/marks every vertex that is

More information

3.4 Testing Bipartiteness

3.4 Testing Bipartiteness 3.4 Testing Bipartiteness Bipartite Graphs Def. An undirected graph G = (V, E) is bipartite (2-colorable) if the nodes can be colored red or blue such that no edge has both ends the same color. Applications.

More information

Goals! CSE 417: Algorithms and Computational Complexity!

Goals! CSE 417: Algorithms and Computational Complexity! Goals! CSE : Algorithms and Computational Complexity! Graphs: defns, examples, utility, terminology! Representation: input, internal! Traversal: Breadth- & Depth-first search! Three Algorithms:!!Connected

More information

Graph Search Methods. Graph Search Methods

Graph Search Methods. Graph Search Methods Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. 0 Graph Search Methods A search method starts at a given vertex v and visits/labels/marks every vertex that is

More information

Lecture 3: Graphs and flows

Lecture 3: Graphs and flows Chapter 3 Lecture 3: Graphs and flows Graphs: a useful combinatorial structure. Definitions: graph, directed and undirected graph, edge as ordered pair, path, cycle, connected graph, strongly connected

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

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

Algorithms: Lecture 7. Chalmers University of Technology

Algorithms: Lecture 7. Chalmers University of Technology Algorithms: Lecture 7 Chalmers University of Technology Today s Lecture Divide & Conquer Counting Inversions Closest Pair of Points Multiplication of large integers Intro to the forthcoming problems Graphs:

More information

Lecture 10 Graph algorithms: testing graph properties

Lecture 10 Graph algorithms: testing graph properties Lecture 10 Graph algorithms: testing graph properties COMP 523: Advanced Algorithmic Techniques Lecturer: Dariusz Kowalski Lecture 10: Testing Graph Properties 1 Overview Previous lectures: Representation

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

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

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 5 Exploring graphs Adam Smith 9/5/2008 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Puzzles Suppose an undirected graph G is connected.

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

COP 4531 Complexity & Analysis of Data Structures & Algorithms

COP 4531 Complexity & Analysis of Data Structures & Algorithms COP Complexity & Analysis of Data Structures & Algorithms Overview of Graphs Breadth irst Search, and Depth irst Search hanks to several people who contributed to these slides including Piyush Kumar and

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

W4231: Analysis of Algorithms

W4231: Analysis of Algorithms W4231: Analysis of Algorithms 10/21/1999 Definitions for graphs Breadth First Search and Depth First Search Topological Sort. Graphs AgraphG is given by a set of vertices V and a set of edges E. Normally

More information

implementing the breadth-first search algorithm implementing the depth-first search algorithm

implementing the breadth-first search algorithm implementing the depth-first search algorithm Graph Traversals 1 Graph Traversals representing graphs adjacency matrices and adjacency lists 2 Implementing the Breadth-First and Depth-First Search Algorithms implementing the breadth-first search algorithm

More information

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo

More information

CSI 604 Elementary Graph Algorithms

CSI 604 Elementary Graph Algorithms CSI 604 Elementary Graph Algorithms Ref: Chapter 22 of the text by Cormen et al. (Second edition) 1 / 25 Graphs: Basic Definitions Undirected Graph G(V, E): V is set of nodes (or vertices) and E is the

More information

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph: Elementary Graph Algorithms Ref: Chapter 22 of the text by Cormen et al. Representing a graph: Graph G(V, E): V set of nodes (vertices); E set of edges. Notation: n = V and m = E. (Vertices are numbered

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

Objec&ves. Wrap up: Implemen&ng BFS and DFS Graph Applica&on: Bipar&te Graphs. Get out your BFS implementa&on handouts. Feb 2, 2018 CSCI211 - Sprenkle

Objec&ves. Wrap up: Implemen&ng BFS and DFS Graph Applica&on: Bipar&te Graphs. Get out your BFS implementa&on handouts. Feb 2, 2018 CSCI211 - Sprenkle Objec&ves Wrap up: Implemen&ng BFS and DFS Graph Applica&on: Bipar&te Graphs Get out your BFS implementa&on handouts Feb 2, 2018 CSCI211 - Sprenkle 1 Review What are two ways to find a connected component?

More information

Outlines: Graphs Part-2

Outlines: Graphs Part-2 Elementary Graph Algorithms PART-2 1 Outlines: Graphs Part-2 Graph Search Methods Breadth-First Search (BFS): BFS Algorithm BFS Example BFS Time Complexity Output of BFS: Shortest Path Breath-First Tree

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

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

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2019

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2019 CS 580: Algorithm Design and Analysis Jeremiah Blocki Purdue University Spring 2019 Recap: Stable Matching Problem Definition of Stable Matching Problem Gale-Shapley Algorithm Unengaged men propose to

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

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

L22-23: Graph Algorithms

L22-23: Graph Algorithms Indian Institute of Science Bangalore, India भ रत य व ज ञ न स स थ न ब गल र, भ रत Department of Computational and Data Sciences DS 0--0,0 L-: Graph Algorithms Yogesh Simmhan simmhan@cds.iisc.ac.in Slides

More information

Minimum Spanning Trees Ch 23 Traversing graphs

Minimum Spanning Trees Ch 23 Traversing graphs Next: Graph Algorithms Graphs Ch 22 Graph representations adjacency list adjacency matrix Minimum Spanning Trees Ch 23 Traversing graphs Breadth-First Search Depth-First Search 11/30/17 CSE 3101 1 Graphs

More information

Trees. Arash Rafiey. 20 October, 2015

Trees. Arash Rafiey. 20 October, 2015 20 October, 2015 Definition Let G = (V, E) be a loop-free undirected graph. G is called a tree if G is connected and contains no cycle. Definition Let G = (V, E) be a loop-free undirected graph. G is called

More information

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number: Name: Entry number: There are 6 questions for a total of 75 points. 1. Consider functions f(n) = 10n2 n + 3 n and g(n) = n3 n. Answer the following: (a) ( 1 / 2 point) State true or false: f(n) is O(g(n)).

More information

CS4800: Algorithms & Data Jonathan Ullman

CS4800: Algorithms & Data Jonathan Ullman CS4800: Algorithms & Data Jonathan Ullman Lecture 11: Graphs Graph Traversals: BFS Feb 16, 2018 What s Next What s Next Graph Algorithms: Graphs: Key Definitions, Properties, Representations Exploring

More information

CSE 421 Applications of DFS(?) Topological sort

CSE 421 Applications of DFS(?) Topological sort CSE 421 Applications of DFS(?) Topological sort Yin Tat Lee 1 Precedence Constraints In a directed graph, an edge (i, j) means task i must occur before task j. Applications Course prerequisite: course

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

Depth-First Search Depth-first search (DFS) is another way to traverse the graph.

Depth-First Search Depth-first search (DFS) is another way to traverse the graph. Depth-First Search Depth-first search (DFS) is another way to traverse the graph. Motivating example: In a video game, you are searching for a path from a point in a maze to the exit. The maze can be modeled

More information

Algorithms and Theory of Computation. Lecture 3: Graph Algorithms

Algorithms and Theory of Computation. Lecture 3: Graph Algorithms Algorithms and Theory of Computation Lecture 3: Graph Algorithms Xiaohui Bei MAS 714 August 20, 2018 Nanyang Technological University MAS 714 August 20, 2018 1 / 18 Connectivity In a undirected graph G

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 3 Data Structures Graphs Traversals Strongly connected components Sofya Raskhodnikova L3.1 Measuring Running Time Focus on scalability: parameterize the running time

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 310 Advanced Data Structures and Algorithms

CS 310 Advanced Data Structures and Algorithms CS 31 Advanced Data Structures and Algorithms Graphs July 18, 17 Tong Wang UMass Boston CS 31 July 18, 17 1 / 4 Graph Definitions Graph a mathematical construction that describes objects and relations

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

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

MA/CSSE 473 Day 12. Questions? Insertion sort analysis Depth first Search Breadth first Search. (Introduce permutation and subset generation)

MA/CSSE 473 Day 12. Questions? Insertion sort analysis Depth first Search Breadth first Search. (Introduce permutation and subset generation) MA/CSSE 473 Day 12 Interpolation Search Insertion Sort quick review DFS, BFS Topological Sort MA/CSSE 473 Day 12 Questions? Interpolation Search Insertion sort analysis Depth first Search Breadth first

More information

Depth First Search (DFS)

Depth First Search (DFS) Algorithms & Models of Computation CS/ECE 374, Fall 2017 epth First Search (FS) Lecture 1 Thursday, October 2, 2017 Today Two topics: Structure of directed graphs FS and its properties One application

More information

Konigsberg Bridge Problem

Konigsberg Bridge Problem Graphs Konigsberg Bridge Problem c C d g A Kneiphof e D a B b f c A C d e g D a b f B Euler s Graph Degree of a vertex: the number of edges incident to it Euler showed that there is a walk starting at

More information

Searching in Graphs (cut points)

Searching in Graphs (cut points) 0 November, 0 Breath First Search (BFS) in Graphs In BFS algorithm we visit the verices level by level. The BFS algorithm creates a tree with root s. Once a node v is discovered by BFS algorithm we put

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

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

DFS on Directed Graphs BOS. Outline and Reading ( 6.4) Digraphs. Reachability ( 6.4.1) Directed Acyclic Graphs (DAG s) ( 6.4.4) S on irected Graphs OS OR JK SO LX W MI irected Graphs S 1.3 1 Outline and Reading ( 6.4) Reachability ( 6.4.1) irected S Strong connectivity irected cyclic Graphs (G s) ( 6.4.4) Topological Sorting irected

More information

Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M.

Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M. Lecture 9 Graphs Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M. Wootters (2017) 1 Graphs A graph is a set of vertices

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

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

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1 Undirected Graphs Terminology. Free Trees. Representations. Minimum Spanning Trees (algorithms: Prim, Kruskal). Graph Traversals (dfs, bfs). Articulation points & Biconnected Components. Graph Matching

More information

Chapter 22 Elementary Graph Algorithms

Chapter 22 Elementary Graph Algorithms Chapter 22 Elementary Graph Algorithms Graph Representations Graph G = (V,E) Directed Undirected Adjacency Lists Adjacency Matrix Graph Representations Adjacency List: Undirected Memory: Adjacency: Graph

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

(Re)Introduction to Graphs and Some Algorithms

(Re)Introduction to Graphs and Some Algorithms (Re)Introduction to Graphs and Some Algorithms Graph Terminology (I) A graph is defined by a set of vertices V and a set of edges E. The edge set must work over the defined vertices in the vertex set.

More information

Review: Graph Theory and Representation

Review: Graph Theory and Representation Review: Graph Theory and Representation Graph Algorithms Graphs and Theorems about Graphs Graph implementation Graph Algorithms Shortest paths Minimum spanning tree What can graphs model? Cost of wiring

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

Solutions to relevant spring 2000 exam problems

Solutions to relevant spring 2000 exam problems Problem 2, exam Here s Prim s algorithm, modified slightly to use C syntax. MSTPrim (G, w, r): Q = V[G]; for (each u Q) { key[u] = ; key[r] = 0; π[r] = 0; while (Q not empty) { u = ExtractMin (Q); for

More information

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V) Graph Algorithms Graphs Graph G = (V, E) V = set of vertices E = set of edges (V V) Types of graphs Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.) Directed: (u, v) is edge from

More information

CS200: Graphs. Prichard Ch. 14 Rosen Ch. 10. CS200 - Graphs 1

CS200: Graphs. Prichard Ch. 14 Rosen Ch. 10. CS200 - Graphs 1 CS200: Graphs Prichard Ch. 14 Rosen Ch. 10 CS200 - Graphs 1 Graphs A collection of nodes and edges What can this represent? n A computer network n Abstraction of a map n Social network CS200 - Graphs 2

More information

DS UNIT 4. Matoshri College of Engineering and Research Center Nasik Department of Computer Engineering Discrete Structutre UNIT - IV

DS UNIT 4. Matoshri College of Engineering and Research Center Nasik Department of Computer Engineering Discrete Structutre UNIT - IV Sr.No. Question Option A Option B Option C Option D 1 2 3 4 5 6 Class : S.E.Comp Which one of the following is the example of non linear data structure Let A be an adjacency matrix of a graph G. The ij

More information

Graph Algorithms: Chapters Part 1: Introductory graph concepts

Graph Algorithms: Chapters Part 1: Introductory graph concepts UMass Lowell Computer Science 91.503 Algorithms Dr. Haim Levkowitz Fall, 2007 Graph Algorithms: Chapters 22-25 Part 1: Introductory graph concepts 1 91.404 Graph Review Elementary Graph Algorithms Minimum

More information

Adjacent: Two distinct vertices u, v are adjacent if there is an edge with ends u, v. In this case we let uv denote such an edge.

Adjacent: Two distinct vertices u, v are adjacent if there is an edge with ends u, v. In this case we let uv denote such an edge. 1 Graph Basics What is a graph? Graph: a graph G consists of a set of vertices, denoted V (G), a set of edges, denoted E(G), and a relation called incidence so that each edge is incident with either one

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

Graduate Algorithms CS F-15 Graphs, BFS, & DFS

Graduate Algorithms CS F-15 Graphs, BFS, & DFS Grauate Algorithms CS67-206F-5 Graphs, BFS, & DFS Davi Galles Department o Computer Science University o San Francisco 5-0: Graphs A graph consists o: A set o noes or vertices (terms are interchangeable)

More information

Introduction to Graphs. CS2110, Spring 2011 Cornell University

Introduction to Graphs. CS2110, Spring 2011 Cornell University Introduction to Graphs CS2110, Spring 2011 Cornell University A graph is a data structure for representing relationships. Each graph is a set of nodes connected by edges. Synonym Graph Hostile Slick Icy

More information

Graphs. Ouline. Graphs 10/3/2018. An Introduction. A graph G = (V,E) is composed of: An edge e = (u,v) is a pair of vertices

Graphs. Ouline. Graphs 10/3/2018. An Introduction. A graph G = (V,E) is composed of: An edge e = (u,v) is a pair of vertices // Graphs An Introduction Ouline What are Graphs? Applications erminology and Problems Representation (Adj. Mat and Linked Lists) Searching Depth irst Search (DS) Breadth irst Search (BS) Graphs A graph

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

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

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

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department CS473-Algorithms I Lecture 3-A Graphs Graphs A directed graph (or digraph) G is a pair (V, E), where V is a finite set, and E is a binary relation on V The set V: Vertex set of G The set E: Edge set of

More information

Lecture 22 Tuesday, April 10

Lecture 22 Tuesday, April 10 CIS 160 - Spring 2018 (instructor Val Tannen) Lecture 22 Tuesday, April 10 GRAPH THEORY Directed Graphs Directed graphs (a.k.a. digraphs) are an important mathematical modeling tool in Computer Science,

More information

CS521 \ Notes for the Final Exam

CS521 \ Notes for the Final Exam CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( )

More information

Chapter 11: Graphs and Trees. March 23, 2008

Chapter 11: Graphs and Trees. March 23, 2008 Chapter 11: Graphs and Trees March 23, 2008 Outline 1 11.1 Graphs: An Introduction 2 11.2 Paths and Circuits 3 11.3 Matrix Representations of Graphs 4 11.5 Trees Graphs: Basic Definitions Informally, a

More information

Representations of Graphs

Representations of Graphs ELEMENTARY GRAPH ALGORITHMS -- CS-5321 Presentation -- I am Nishit Kapadia Representations of Graphs There are two standard ways: A collection of adjacency lists - they provide a compact way to represent

More information

CSE 417: Algorithms and Computational Complexity

CSE 417: Algorithms and Computational Complexity CSE : Algorithms and Computational Complexity More Graph Algorithms Autumn 00 Paul Beame Given: a directed acyclic graph (DAG) G=(V,E) Output: numbering of the vertices of G with distinct numbers from

More information

Graphs. CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington

Graphs. CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington Graphs CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington 1 Representation Adjacency matrix??adjacency lists?? Review Graphs (from CSE 2315)

More information

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1 CME 305: Discrete Mathematics and Algorithms Instructor: Professor Aaron Sidford (sidford@stanford.edu) January 11, 2018 Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1 In this lecture

More information

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs 2011 Pearson Addison-Wesley. All rights reserved 14 A-1 Terminology G = {V, E} A graph G consists of two sets A set V of vertices, or nodes A set E of edges A subgraph Consists of a subset

More information

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II DIRECTED GRAPHS Graphs slides are modified from COS 126 slides of Dr. Robert Sedgewick. 1 Directed graphs Digraph Set of vertices connected pairwise by directed

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

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

GRAPHS Lecture 17 CS2110 Spring 2014

GRAPHS Lecture 17 CS2110 Spring 2014 GRAPHS Lecture 17 CS2110 Spring 2014 These are not Graphs 2...not the kind we mean, anyway These are Graphs 3 K 5 K 3,3 = Applications of Graphs 4 Communication networks The internet is a huge graph Routing

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

Theory of Computing. Lecture 4/5 MAS 714 Hartmut Klauck

Theory of Computing. Lecture 4/5 MAS 714 Hartmut Klauck Theory of Computing Lecture 4/5 MAS 714 Hartmut Klauck How fast can we sort? There are deterministic algorithms that sort in worst case time O(n log n) Do better algorithms exist? Example [Andersson et

More information

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