Keys to Success: CAR Theorem CHAPTER 3 GRAPHS. Outline. Basics. Definitions and applications. Iris Hui-Ru Jiang Fall 2014.
|
|
- Miranda Sims
- 6 years ago
- Views:
Transcription
1 Keys to Success: CAR Theorem Prof. Chang s CAR Theorem Iris: Recap stable matching Criticality Extract the essence Identify the clean core Remoe extraneous detail CHAPTER GRAPHS Iris Hui-Ru Jiang Fall 0 Abstraction Restriction Represent in an abstract form First think at high-leel Deise the algorithm Then go down to low-leel Complete implementation Simplify unimportant things List the limitations Show how to extend Prof. Yao-Wen Chang@NTU Outline Content: Basic definitions and applications Graph connectiity and graph traersal Implementation Testing bipartiteness: an application of BFS Connectiity in directed graphs Directed acyclic graphs and ological ordering Reading: Chapter Basics Definitions and applications
2 Salute to Euler! Examples of (/) Our focus in this course is on problems with a discrete flaor. One of the most fundamental and expressie of combinatorial structures is the graph. Inented by L. Euler based on his proof on the Königsberg bridge problem (the seen bridge problem) in. Is it possible to walk across all the bridges exactly once and return to the starting land area? Abstraction! It s useful to digest the meaning of the nodes and the meaning of the edges in the following examples. It s not important to remember them. Transportation networks: No Eulerian walk China Airlines international route map (node: city; edge: non-s flight) London underground map (node: station; edge: adjacent stations) L. Euler, Solutioproblematis ad geometriamsituspertinentis, Commentarii Academiae Scientiarum Imperialis Petropolitanae, Vol., pp. 0, (published ). (H. Beck, ) Graph ( ) Examples of (/) A graph is simply a way of encoding pairwise relationships among a set of objects. A graphg = (V, E) consists of A collection V of nodes (a.k.a. ertices) A collection E of edges Each edge joins two nodes e = {u, } Î E for some u, Î V In an undirected graph: symmetric relationships Edges are undirected, i.e., {u, } == {, u} e.g., u and are family. In a directed graph: asymmetric relationships Edges are directed, i.e., (u, )!= (, u) u u tail head e.g., u knows (celebrity), while doesn t know u. is one of u sneighbor if there is an edge (u, ) Adjacency Communication networks Wireless sensor network (node: sensor; edge: signal broadcasting)
3 Examples of (/) Examples of (/) Information networks Dependency networks World Wide Web (node: webpage; edge: hyperlink) Food chain/web (node: species; edge: from prey to predator) Examples of (/) Examples of (/) 0 Social networks Technological Network Facebook (node: people; edge: friendship) Finite state machine (node: state; edge: state transition)
4 Paths and Connectiity (/) Trees One of the fundamental operations in a graph is that of traersing a sequence of nodes connected by edges. Browse Web pages by following hyperlinks Join a 0-day tour from Taipei to Europe on a sequence of flights Pass gossip by word of mouth (by message of mobile phone) from you to someone far away Hey upper east siders, Gossip Girl here! -- Gossip Girl An undirected graph is a tree if it is connected and does not contain a cycle. Trees are the simplest kind of connected graph: deleting any edge will disconnect it. Thm: Let G be an undirected graph on n nodes. Any two of the following statements imply the third. G is connected. G does not contain a cycle. G has n- edges. G is a tree if it satisfies any two of the three statements Tree? Grab and let the rest hang downward Yes! Paths and Connectiity (/) A path in an undirected graph G = (V, E) is a sequence P of nodes,,, k-, k with the property that each consecutie pair i, i+ is joined by an edge in E. A path is simple if all nodes are distinct. A cycle is a path,,, k-, k in which = k, k>, and the first k- nodes are all distinct. An undirected graph is connected if, for eery pair of nodes u and, there is a path from u to. The distance between nodes u and is the minimum number of edges in a u- path. ( for disconnected) Note: These definitions carry oer naturally to directed graphs with respect to the directionality of edges. Path P =,,,,,, Cycle C =,,,,, Rooted Trees A rooted tree is a tree with its root at r. Grab and let the rest hang downward root r s parent a tree the same tree, rooted at Rooted trees encode the notion of a hierarchy. e.g., sitemap of a Web site The tree-like structure facilitates naigation (root: entry page) Directed edges: asymmetric relationship s child leaf
5 Breadth-First-Search (BFS) Graph Connectiity and Graph Traersal BFS DFS Breadth-first search (BFS): propagate the waes Start at s and flood the graph with an expanding wae that grows to isit all nodes that it can reach. Layer L i : i is the time that a node is reached. Adjacent nodes Layer L 0 = {s}; layer L = all neighbors of L 0. Layer L j+ = all nodes that do not belong to an earlier layer and that are neighbors of L j. i = distance between s to the nodes that belong to layer L i. L L L L Node-to-Node Connectiity BFS Tree Q: Gien a graph G = (V, E) and two particular nodes s and t, is there a path from s to t in G? The s-t connectiity problem The maze-soling problem A: For small graphs, easy! (isual inspection) - connectiity? - connectiity? What if large graphs? How efficiently can we do? 0 room hallway 0 Let T be a BFS tree, let x and y be nodes in T belonging to layers L i and L j respectiely, and let (x, y) be an edge of G. Then i and j differ by at most. Pf: Without loss of generality, suppose j i >. By definition, xîl i, x s neighbors belongs to L i+ or earlier. Since (x, y) is an edge of G, y is x s neighbor, yî L j and j! i+. BFS tree L L L L 0 Nontree edge L 0 L L BFS tree Tree edge L
6 Connected Component Connected Component s R A connected component containing s is the set of nodes that are reachable from s. Connected component containing node is {,,,,,,, }. There are three connected components. The other two are {, 0} and {,, }. 0 Find all nodes reachable from s: Connected-Component(s) // R will consist of nodes to which s has a path. initialize R = {s}. while (there is an edge (u, ) where uîr andïr) do. R = R + {} it's safe to add Correctness: Upon termination, R is the connected component containing s. Pf: Q: How about any node ÎR? Q: How about a node wïr? Q: How to recoer the actual path from s to any node tîr? Q: How to explore a new edge in line? BFS: explore in order of distance from s. Any method else? u Color Fill Depth-First Search (DFS) Q: Gien lime green pixel in an image, how to change color of entire blob of neighboring lime pixels to blue? A: Model the image as a graph. Node: pixel. Edge: two neighboring lime pixels. Blob: connected component of lime pixels. recolor lime green blob to blue Depth-first search (DFS): Go as deeply as possible or retreat Start from s and try the first edge leading out, and so on, until reach a dead end. Backtrack and repeat. A mouse in a maze without the map. Another method for finding connected component DFS(u). mark u as explored and add u to R. foreach edge (u, ) incident to u do. if ( is not marked as explored) then. recursiely inoke DFS()
7 DFS Tree Let T be a DFS tree, let x and y be nodes in T, and let (x, y) be a nontree edge. Then one of x or y is an ancestor of the other. Pf: descendant WLOG, suppose x is reached first by DFS. When (x, y) is examined during DFS(x), it is not added to T because y is marked explored. Since y is not marked as explored when DFS(x) was first inoked, it is a node that was discoered between the inocation and end of the recursie call DFS(x). DFS tree DFS tree y is a descendant of x. Implementation Lists / arrays Queues / stacks Nontree edge Tree edge 0 Summary: BFS and DFS Representing Similarity: BFS/DFS builds the connected component containing s. Difference: BFS tree is flat/short; DFS tree is narrow/deep. What are the nontree edges in BFS/DFS? Q: How to produce all the connected components of a graph? A: A graph G = (V, E) V = the number of nodes = n E = the number of edges = m cardinality (size) of a set Dense or sparse? n For a connected graph, n! m!! n Linear time = O(m+n) Why? It takes O(m+n) to read the input 0
8 Adjacency Matrix What is a Queue? Two open ended container Consider a graph G = (V, E) with n nodes, V = {,, n}. The adjacency matrix of G is an nxn martix A where A[u, ] = if (u, ) Î E; A[u, ] = 0, otherwise. Time: Q() time for checking if (u, ) Î E. Q(n) time for finding out all neighbors of some u Î V. Visit many 0 s Space: Q(n ) What if sparse graphs? symmetric A queue is a set of elements from which we extract elements in first-in, first-out (FIFO) order. We select elements in the same order in which they were added. Q = (a,..., a n ) front rear Push (A) A Push (B) A B Push (C) A B C Push (D) front, rear front A B C D rear Pop () front front rear B C D rear front Push (E) front front rear Pop a a a n rear B C D E Push rear Adjacency List What is a Stack? One open ended and one close ended container 0 The adjacency list of G is an array Adj[]of n lists, one for each node represents its neighbors Adj[u] = a linked list of { (u, ) ÎE}. Time: degree of u: number of neighbors Q(deg(u)) time for checking one edge or all neighbors of a node. Space: O(n+m) [] [] 0 [] [] [] [] m 0 A stack is a set of elements from which we extract elements in last-in, first-out (LIFO) order. Each time we select an element, we choose the one that was added most recently. A S = (a,..., a n ) bottom B A C B A D C B A bottom a E D C B A a a n D C B A Pop Push [] [] 0 0 Push (A) Push (B) Push (C) Push (D) Push (E) Pop( ) = E
9 Linked Stacks and Queues Implementing DFS Implement queues and stacks by linked lists datalink... 0 Linked stack Pop Push Pop front data link Linked queue Adantage? - Variable sizes - Insert/delete in O() Push rear 0 We implement DFS by adjacency list Recursie procedure DFS(u). mark u as explored and add u to R. foreach edge (u, ) incident to u do. if ( is not marked as explored) then. recursiely inoke DFS() Alternatie implementation of DFS Process each adjacency list in the reerse order DFS(s) // S: a stack of nodes whose neighbors haen t been entirely explored. S = {s}. while (S is not empty) do. remoe a node u from S. if (Explored[u] = false) then. Explored[u] = true. for each (edge (u, ) incident to u) do. S = S + {} Q: Running time? O(n ) or O(n+m) Why? Implementing BFS Adjacency list is ideal for implementing BFS BFS(s) // T will be BFS tree rooted at s; layer counter i; layer list L[i]. Discoered[s] = true; Discoered[] = false for other. i = 0; L[0] = {s}; T = {};. while (L[i] is not empty) do. L[i+] = {};. for each (node uîl[i]) do. for each (edge (u, ) incident to u) do. if (Discoered[] = false) then. Discoered[] = true. T = T + {(u, )} 0. L[i+] = L[i+] + {}. i++ Q: How to manage each layer list L[i]? A: A queue/stack is fine Nodes in L[i] can be in any order Or, we can merge all layer lists into a single list L as a queue L L Q: Running time? O(n ) or O(n+m) Why? L L 0 Summary: Implementation Graph: Adjacency matrix s. Adjacency list Faster to find an edge? Faster to find degree? Faster to traerse the graph? Storage for sparse graph? Storage for dense graph? Edge insertion or deletion? Better for most applications? Graph traersal BFS: queue (or stack) DFS: stack O(n+m) time Winner Matrix List List List Matrix Matrix List
10 Is a Graph Bipartite? Testing Bipartiteness Q: Gien a graph G, is it bipartite? A: Color the nodes with blue and red (two-coloring) Application of BFS If a graph G is bipartite, then it cannot contain an odd cycle. Bipartite A bipartite graph (bigraph) is a graph whose nodes can be partitioned into sets X and Y in such a way that eery edge has one one end in X and the other end in Y. X and Y are two disjoint sets. No two nodes within the same set are adjacent. X Y G = (X, Y, E) 0 Testing Bipartiteness Color the nodes with blue and red Procedure: Arbitrarily chosen. Assume G = (V, E) is connected. Otherwise, we analyze connected components separately.. Pick any node sîv and color it red Anyway, s must receie some color.. Color all the neighbors of s blue.. Repeat coloring red/blue until the whole graph is colored.. Test bipartiteness: eery edge has ends of opposite colors. X Y
11 Implementation: Testing Bipartiteness Q: How to implement this procedure? Arbitrarily chosen A: BFS! O(m+n)-time We perform BFS from any s, coloring s red, all of layer L blue, Een/odd-numbered layers red/blue Insert the following statements after line 0 of BFS(s) (p. ) 0. L[i+] = L[i+] + {} 0a. if ((i+) is een) then 0b. Color[] = red 0c. else 0d. Color[] = blue X Y Proof: Correctness (/) Pf: (Case ) Suppose (x, y) is an edge with x, y in same layer L j. Let z = lca(x, y) = lowest common ancestor. Let L i be the layer containing z. Consider the cycle that takes edge from x to y, then path from y to z, then path from z to x. Its length is + (j-i) + (j-i), which is odd. x z = lca(x, y) (x, y) y ->z z ->x z Let xîl i, yîl j, and (x, y) ÎE. Then i and j differ by at most. s y L 0 L i L j Proof: Correctness (/) Let G be a connected graph and let L 0, L, be the layers produced by BFS starting at node s. Then exactly one of the following holds.. No edge of G joins two nodes of the same layer, and G is bipartite.. An edge of G joins two nodes of the same layer, and G contains an odd-length cycle (and hence is not bipartite). Pf: Case is triial. Connectiity in Directed L 0 L L L L 0 L L L Let xîl i, yîl j, and (x, y) ÎE. Then i and j differ by at most.
12 Recap: Directed Testing Strong Connectiity In a directed graph: asymmetric relationships u (u, ) Edges are directed, i.e., (u, )!= (, u) tail head e.g., u knows (celebrity), while doesn t know u. Directionality is crucial. Representation: Adjacency list Each node is associated with two lists, instead of one in an undirected graph. To which From which Graph search algorithms: BFS/DFS Almost the same as undirected graphs Again, directionality is crucial. Q: What can we reach from node? A: Q: Can we determine if a graph is strongly connected in linear time? A: Yes. How? Why? TestSC(G). pick any node s in G G re : reerse the direction of eery edge in G. R = BFS(s, G) (u, ) in G re if (, u)in G. R re = BFS(s, G re ). if (R = V = R re ) then return true else false Time: O(m+n) R = V = R Q: Correctness? re s Q: How to partition a directed graph into strong components? u Strong Connectiity Strong Component Nodes u and are mutually reachable if there is a path from u to and also a path from to u. u The strong component containing s in a directed graph is the maximal set of all s.t. s and are mutually reachable. a.k.a. strongly connected component A directed graph is strongly connected if eery pair of nodes are mutually reachable. Q: When are there no mutually reachable nodes? Lemma: If u and are mutually reachable, and and w are mutually reachable, then u and w are mutually reachable. Simple but important! Pf: Theorem: For any two nodes s and t in a directed graph, their strong components are either identical or disjoint. Q: When are they identical? When are they disjoint? Pf: Identical if s and t are mutually reachable s --, s -- t, -- t Disjoint if s and t are not mutually reachable Proof by contradiction u w u w
13 Topological Ordering DAGs and Topological Ordering Q: driers come to the junction simultaneously, who goes first? Deadlock! Dependencies form a cycle! The drier must come to a complete s at a s sign. Generally the drier who arries and ss first continues first. If two or three driers in different directions s simultaneously at a junction controlled by s signs, generally the driers on the left must yield the right-of-way to the drier on the far right. Gien a directed graph G, a ological ordering is an ordering of its nodes as,,, n so that for eery edge ( i, j ), we hae i<j. Precedence constraints: edge ( i, j ) means i must precede j. Lemma: If G has a ological ordering, then G is a DAG. Pf: Proof by contradiction! How? Consider a cycle, i,, j, i. i j Directed Acyclic Example 0 Q: If an undirected graph has no cycles, then what s it? A: A tree (or forest). At most n- edges. A directed acyclic graph (DAG) is a directed graph without cycles. A DAG may hae a rich structure. A DAG encodes dependency or precedence constraints e.g., prerequisite of Algorithms: Data structures Discrete math Programming C/C++ e.g., execution order of instructions in CPU Pipeline structures Example: a DAG Lemma: If G has a ological ordering, then G is a DAG. Q: If G is a DAG, then does G hae a ological ordering? Q: If so, how do we compute one? A: Key: find a way to get started! Q: How? the same DAG with ological ordering
14 Where to Start? w x u Topological Ordering A: A node that depends on no one, i.e., unconstrained. Lemma: In eery DAG G, there is a node with no incoming edges. Pf: Proof by contradiction! Suppose that G is a DAG where eery node has at least one incoming edge. Let's see how to find a cycle in G. Pick any node, and begin following edges backward from : Since has at least one incoming edge (u, ) we can walk backward to u. Then, since u has at least one incoming edge (x, u), we can walk backward to x; and so on. Repeat this process n+ times (the initial counts one). We will isit some node w twice, since G has only n nodes. Let C denote the sequence of nodes encountered between successie isits to w. Clearly, C is a cycle. Lemma: If G is a DAG, then G has a ological ordering. Pf: Proof by induction!. Base case: true if n =.. Inductie step: Induction hypothesis: true for DAGs with up to n nodes Gien a DAG on n+ nodes, find a node w/o incoming edges. G {} + <,,, n > = <,,,, n > G {} is a DAG, since deleting cannot create any cycles. G {} has n nodes. By induction hypothesis, G {} has a ological ordering. Place first in ological ordering. This is safe since all edges of point forward. Then append nodes of G {} in ological order after. Example: Topological Ordering A Linear-Time Algorithm In fact, the proof has already suggested an algorithm. TopologicalOrder(G). find a node without incoming edges. order. G = G {} // delete from G. if (G is not empty) then TopologicalOrder(G) Time: From O(n ) to O(m+n) O(n )-time: Total n iterations; line in O(n)-time. How? O(m+n)-time: How? Maintain the following information indeg(w) = # of incoming edges from undeleted nodes S = set of nodes without incoming edges from undeleted nodes Initialization: O(m+n) ia single scan through graph Update: line deletes Remoe from S Decrement indeg(w) for all edges from to w, and add w to S if indeg(w) hits 0; this is O() per edge
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 informationUndirected 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 information3.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 informationAlgorithm 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 informationChapter 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 informationCS781 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 informationLecture 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 informationCopyright 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 informationCSE 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 informationAlgorithms: 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 informationCopyright 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 information3.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 informationChapter 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 informationChapter 3. Graphs. 3.1 Basic Definitions and Applications
Chapter 3 Graphs Our focus in this book is on problems with a discrete flavor. Just as continuous mathematics is concerned with certain basic structures such as real numbers, vectors, and matrices, discrete
More informationGraph 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 information3.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 informationGoals! 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 informationCSE 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 informationPlan. 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 informationAlgorithm 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 information3. 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 informationGraph. 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 informationLecture 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 informationChapter 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 informationCS 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 informationCS 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 informationIntroduction to Algorithms
6.006- Introduction to Algorithms Lecture 13 Prof. Constantinos Daskalakis CLRS 22.4-22.5 Graphs G=(V,E) V a set of vertices Usually number denoted by n E VxV a set of edges (pairs of vertices) Usually
More informationGraphs. 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 informationGraph theory: basic concepts
Graph theory: basic concepts Graphs and networks allow modelling many different decision problems Graphs permit to represent relationships among different kinds of entities: Cities connected by roads Computers
More informationGraph: 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 informationStrongly 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 informationGRAPHS (Undirected) Graph: Set of objects with pairwise connections. Why study graph algorithms?
GRAPHS (Undirected) Graph: Set of objects with pairwise connections. Why study graph algorithms? Interesting and broadly useful abstraction. Challenging branch of computer science and discrete math. Hundreds
More informationObjec&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 informationElementary 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 informationGraph 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 informationScribes: 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 informationKonigsberg 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 informationGraph 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 informationCOL351: 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 informationGraph 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 informationCSI 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 informationGraph 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 informationW4231: 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 informationGraph Theory CS/Math231 Discrete Mathematics Spring2015
1 Graphs Definition 1 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 is called the vertex set of G, and its elements are called vertices
More informationCS473-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 informationimplementing 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 informationOutline. 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 informationChapter 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 informationNotes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 9 Notes. Class URL:
Notes slides from before lecture CSE 21, Winter 2017, Section A00 Lecture 9 Notes Class URL: http://vlsicad.ucsd.edu/courses/cse21-w17/ Notes slides from before lecture Notes February 8 (1) HW4 is due
More informationSolutions 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 informationFundamental Graph Algorithms Part Three
Fundamental Graph Algorithms Part Three Outline for Today Topological Sorting, Part II How can we quickly compute a topological ordering on a DAG? Connected Components How do we find the pieces of an undirected
More informationCS521 \ 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 informationWeek 9-10: Connectivity
Week 9-0: Connectiity October 3, 206 Vertex Connectiity Let G = (V, E) be a graph. Gien two ertices x, y V. Two (x, y)-path are said to be internally disjoint if they hae no internal ertices in common.
More informationCSE 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 informationTIE Graph algorithms
TIE-20106 239 11 Graph algorithms This chapter discusses the data structure that is a collection of points (called nodes or vertices) and connections between them (called edges or arcs) a graph. The common
More informationCS 125 Section #6 Graph Traversal and Linear Programs 10/13/14
CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14 1 Depth first search 1.1 The Algorithm Besides breadth first search, which we saw in class in relation to Dijkstra s algorithm, there is one
More informationGraph 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 informationMA/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 informationAlgorithms 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 informationLecture 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 informationBACKGROUND: 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 informationTIE Graph algorithms
TIE-20106 1 1 Graph algorithms This chapter discusses the data structure that is a collection of points (called nodes or vertices) and connections between them (called edges or arcs) a graph. The common
More informationMatching Algorithms. Proof. If a bipartite graph has a perfect matching, then it is easy to see that the right hand side is a necessary condition.
18.433 Combinatorial Optimization Matching Algorithms September 9,14,16 Lecturer: Santosh Vempala Given a graph G = (V, E), a matching M is a set of edges with the property that no two of the edges have
More informationDefinition For vertices u, v V (G), the distance from u to v, denoted d(u, v), in G is the length of a shortest u, v-path. 1
Graph fundamentals Bipartite graph characterization Lemma. If a graph contains an odd closed walk, then it contains an odd cycle. Proof strategy: Consider a shortest closed odd walk W. If W is not a cycle,
More informationLecture 5: Graphs. Rajat Mittal. IIT Kanpur
Lecture : Graphs Rajat Mittal IIT Kanpur Combinatorial graphs provide a natural way to model connections between different objects. They are very useful in depicting communication networks, social networks
More informationCSCE 750, Fall 2002 Notes 6 Page Graph Problems ffl explore all nodes (breadth first and depth first) ffl find the shortest path from a given s
CSCE 750, Fall 2002 Notes 6 Page 1 10 Graph Algorithms (These notes follow the development in Cormen, Leiserson, and Rivest.) 10.1 Definitions ffl graph, directed graph (digraph), nodes, edges, subgraph
More informationThe Konigsberg Bridge Problem
The Konigsberg Bridge Problem This is a classic mathematical problem. There were seven bridges across the river Pregel at Königsberg. Is it possible to take a walk in which each bridge is crossed exactly
More informationGraph 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 informationIntroduction 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 informationDepth-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 information12. Graphs. Königsberg Cycles. [Multi]Graph
Königsberg 76. Graphs Notation, Representation, Graph Traversal (DFS, BFS), Topological Sorting, Ottman/Widmayer, Kap. 9. - 9.,Cormen et al, Kap. [Multi]Graph Cycles C edge Is there a cycle through the
More informationDiscrete mathematics , Fall Instructor: prof. János Pach
Discrete mathematics 2016-2017, Fall Instructor: prof. János Pach - covered material - Lecture 1. Counting problems To read: [Lov]: 1.2. Sets, 1.3. Number of subsets, 1.5. Sequences, 1.6. Permutations,
More informationLecture 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 informationData Structure. IBPS SO (IT- Officer) Exam 2017
Data Structure IBPS SO (IT- Officer) Exam 2017 Data Structure: In computer science, a data structure is a way of storing and organizing data in a computer s memory so that it can be used efficiently. Data
More informationAlgorithm Design (8) Graph Algorithms 1/2
Graph Algorithm Design (8) Graph Algorithms / Graph:, : A finite set of vertices (or nodes) : A finite set of edges (or arcs or branches) each of which connect two vertices Takashi Chikayama School of
More informationBIL694-Lecture 1: Introduction to Graphs
BIL694-Lecture 1: Introduction to Graphs Lecturer: Lale Özkahya Resources for the presentation: http://www.math.ucsd.edu/ gptesler/184a/calendar.html http://www.inf.ed.ac.uk/teaching/courses/dmmr/ Outline
More informationAlgorithm 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 informationGRAPHS 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 informationGraphs. 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 informationLecture 6: Graph Properties
Lecture 6: Graph Properties Rajat Mittal IIT Kanpur In this section, we will look at some of the combinatorial properties of graphs. Initially we will discuss independent sets. The bulk of the content
More informationDesign and Analysis of Algorithms
CSE, Winter 8 Design and Analysis of Algorithms Lecture : Graphs, DFS (Undirected, Directed), DAGs Class URL: http://vlsicad.ucsd.edu/courses/cse-w8/ Graphs Internet topology Graphs Gene-gene interactions
More informationCS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019
CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction
More informationCSE 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 informationFundamental Properties of Graphs
Chapter three In many real-life situations we need to know how robust a graph that represents a certain network is, how edges or vertices can be removed without completely destroying the overall connectivity,
More informationAnnouncements. 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 informationLECTURE 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 informationLecture 8: PATHS, CYCLES AND CONNECTEDNESS
Discrete Mathematics August 20, 2014 Lecture 8: PATHS, CYCLES AND CONNECTEDNESS Instructor: Sushmita Ruj Scribe: Ishan Sahu & Arnab Biswas 1 Paths, Cycles and Connectedness 1.1 Paths and Cycles 1. Paths
More informationGraphs and trees come up everywhere. We can view the internet as a graph (in many ways) Web search views web pages as a graph
Graphs and Trees Graphs and trees come up everywhere. We can view the internet as a graph (in many ways) who is connected to whom Web search views web pages as a graph Who points to whom Niche graphs (Ecology):
More informationGraph Search. Algorithms & Models of Computation CS/ECE 374, Fall Lecture 15. Thursday, October 19, 2017
Algorithms & Models of Computation CS/ECE 374, Fall 2017 Graph Search Lecture 15 Thursday, October 19, 2017 Sariel Har-Peled (UIUC) CS374 1 Fall 2017 1 / 50 Part I Graph Basics Sariel Har-Peled (UIUC)
More informationData 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 informationGraph Search. CS/ECE 374: Algorithms & Models of Computation, Fall Lecture 15. October 18, 2018
CS/ECE 374: Algorithms & Models of Computation, Fall 2018 Graph Search Lecture 15 October 18, 2018 Chandra Chekuri (UIUC) CS/ECE 374 1 Fall 2018 1 / 45 Part I Graph Basics Chandra Chekuri (UIUC) CS/ECE
More informationTheory 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 informationLecture 20 : Trees DRAFT
CS/Math 240: Introduction to Discrete Mathematics 4/12/2011 Lecture 20 : Trees Instructor: Dieter van Melkebeek Scribe: Dalibor Zelený DRAFT Last time we discussed graphs. Today we continue this discussion,
More informationPERFECT MATCHING THE CENTRALIZED DEPLOYMENT MOBILE SENSORS THE PROBLEM SECOND PART: WIRELESS NETWORKS 2.B. SENSOR NETWORKS OF MOBILE SENSORS
SECOND PART: WIRELESS NETWORKS 2.B. SENSOR NETWORKS THE CENTRALIZED DEPLOYMENT OF MOBILE SENSORS I.E. THE MINIMUM WEIGHT PERFECT MATCHING 1 2 ON BIPARTITE GRAPHS Prof. Tiziana Calamoneri Network Algorithms
More informationLecture 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 informationCOS 423 Lecture14. Robert E. Tarjan 2011
COS 423 Lecture14 Graph Search Robert E. Tarjan 2011 An undirected graph 4 connected components c a b g d e f h i j Vertex j is isolated: no incident edges Undirected graph search G= (V, E) V= vertex set,
More informationSome major graph problems
CS : Graphs and Blobs! Prof. Graeme Bailey http://cs.cs.cornell.edu (notes modified from Noah Snavely, Spring 009) Some major graph problems! Graph colouring Ensuring that radio stations don t clash! Graph
More informationMinimum Spanning Trees Ch 23 Traversing graphs
Net: Graph Algorithms Graphs Ch 22 Graph representations adjacenc list adjacenc matri Minimum Spanning Trees Ch 23 Traersing graphs Breadth-First Search Depth-First Search 7/16/2013 CSE 3101 1 Graphs Definition
More informationBasic Combinatorics. Math 40210, Section 01 Fall Homework 4 Solutions
Basic Combinatorics Math 40210, Section 01 Fall 2012 Homework 4 Solutions 1.4.2 2: One possible implementation: Start with abcgfjiea From edge cd build, using previously unmarked edges: cdhlponminjkghc
More informationAlgorithms: Graphs. Amotz Bar-Noy. Spring 2012 CUNY. Amotz Bar-Noy (CUNY) Graphs Spring / 95
Algorithms: Graphs Amotz Bar-Noy CUNY Spring 2012 Amotz Bar-Noy (CUNY) Graphs Spring 2012 1 / 95 Graphs Definition: A graph is a collection of edges and vertices. Each edge connects two vertices. Amotz
More information