Overview. CSE 548: (Design and) Analysis of Algorithms. Definition and Representations
|
|
- Rachel Stafford
- 6 years ago
- Views:
Transcription
1 Overview Overview S 548: (esign and) nalysis of lgorithms raphs R. Sekar raphs provide a concise representation of a range problems Map coloring more generally, resource contention problems Figure Networks 3.1 (a) mapcommunication, and (b) its graph. traffic, social, biological,... (a) (b) / / 30 Overview efinition and Representations graph = (V, ), where V is a set of vertices, and a set of edges. n edge e of the form (v1, v2) is said to span vertices v1 and v2. The edges in a directed graph are directed. = (V, ) is called a subgraph of if V V and includes every edge in between vertices in V. djacency matrix graph (V = {v1,..., vn}, ) can be represented by an n n matrix a, where aij = 1 iff (vi, vj) djacency list ach vertex v is associated with a linked list consisting of all vertices u such that (v, u). Note that adjacency matrix uses O(n 2 ) storage, while adjacency list uses O( V + ) storage. oth can represent directed as well as undirected graphs. 3 / 30 necessary to use edges with directions on them. There can be directed edges e from x to y (written e = (x, y)), or from y to x (written (y, x)), or both. particularly enormous example of a directed graph is the graph of all links in the World Wide Web. It has a vertex for each Introsite FSon iconnectivity the Internet, s and Sa directed FS Paths edge and Matrices (u, v) whenever site u has a link to site v: in total, billions of nodes and edges! Understanding even the most basic connectivity properties of the Web is of great economic and social interest. lthough the size of this problem is daunting, epth-first we will soon see that asearch lot of valuable information (FS) about the structure of a graph can, happily, be determined in just linear time technique How is afor graph traversing represented? all vertices in the graph We Very canversatile, represent a graph forms bythe an adjacency linchpin matrix; of many if theregraph are n = algorithms V vertices v1,..., vn, this is an n n array whose (i, j)th entry is 1 if there is an edge from vi to vj dfs(v, ) aij = 0 otherwise. foreach For undirected v graphs, V dothe visited[v] matrix symmetric = falsesince an edge {u, v} can be taken in either foreach direction. v V do The biggest convenience of this format is that the presence of a particular edge can be checked if not invisited[v] constant time, then with just explore(v one memory,, access. v) On the other hand the matrix takes up O(n 2 ) space, which is wasteful if the graph does not have very many edges. n alternative representation, with size proportional to the number of edges, is the adjacency list., It, consists v) of V linked lists, one per vertex. The linked list for vertex u holds the explore(v names of vertices to which u has an outgoing edge that is, vertices v for which (u, v). visited[v] = true 88 previsit(v) /* placeholder for now*/ foreach (v, u) do if not visited[u] then explore(, V, u) postvisit(v) /*nother placeholder*/ 4 / 30
2 raphs, Mazes and FS Figure 3.2 xploring a graph is rather like navigating a maze. graph and its FS tree Figure 3.4 The result of explore() on the graph of Figure 3.2. Figure 3.2 xploring a graph is rather like navigating a maze. F H F H F I J J H F I J I J F H I Figure If a maze 3.3 Finding is represented all nodes reachable as a from graph, a particular then FS node. of the graph amounts procedure explore(, v) to an exploration and mapping of the maze. Input: = (V, ) is a graph; v V Output: visited(u) is set to true for all nodes u reachable from v visited(v) = true 5 / 30 previsit(v) for each edge (v, u) : if not visited(u): explore(u) postvisit(v) FS and onnected omponents and whenever you arrive at any junction (vertex) there are a variety of passages (edges) you Figure can follow. 3.6 (a) careless 12-node choice graph. of passages (b) FSmight searchlead forest. you around in circles or might cause you to overlook some accessible part of the maze. learly, you need to record some intermediate 1,10 11,22 23,24 information during exploration. (a) (b) This classic challenge has amused people for centuries. verybody knows that all youf need to explore a labyrinth is aball of string and a piece of chalk. The chalk prevents looping, by marking the junctions you have already visited. The string 4,9 always takes 12,21 you back to the starting place, enabling you to return to passages 2,3that you previously saw but did not yet investigate. F H I 5,8 13,20 H How can we simulate these two primitives, chalk and string, on a computer? The chalk marks are easy: for each vertex, maintain a oolean variable indicating whether it has been visited I already. J s forthe ball of string, the correct cyberanalog J is a14,17 stack. fter all, the exact role of the string is to offer two primitive operations unwind 6,7 to get to a new junction 18,19 (the stack equivalent is to push the new vertex) and rewind to return to the previous junction (pop the stack). 15,16 Instead of explicitly maintaining a stack, we will do so implicitly via recursion (which is implemented using a stack of activation records). The resulting algorithm is shown in connected component of a graph is a maximal subgraph where 90 These there regions is path are called between connected anycomponents: two vertices eachin of them subgraph, is a i.e., that itisisinternally a connected but has no edges to the remaining vertices. When explore is started at a particular vertex, maximal it identifies connected preciselysubgraph. the connected component containing that vertex. nd each time the FS outer loop calls explore, a new connected component is picked out. 7 / 30 Thus depth-first search is trivially adapted to check if a graph is connected and, more generally, to assign each node v an integer ccnum[v] identifying the connected component to J I FS uses O( V ) space Figure and 3.5O( epth-first + V search. ) time. procedure dfs() Figure 3.3 Finding all nodes reachable from a particular node. for all v V : 6 / 30 procedure explore(, visited(v) v) = false Input: = (V, ) is a graph; v V Output: visited(u) for allis v set V : to true for all nodes u reachable if not visited(v): explore(v) visited(v) = true previsit(v) FS Numbering for each edge (v, u) : if not visited(u): This loop takes explore(u) a different amount of time for each vertex, so let s co postvisit(v) gether. The total work done in step 1 is then O( V ). In step 2, over t ssociate post andfs, pre each numbers edge {x, with y} each is examined visited node exactly bytwice, defining once during expl ing explore(y). The overall time for step 2 is therefore O( ) and so previsit and postvisit has a running time of O( V + ), linear in the size of its input. Th could possibly hope for, since it takes this long even just to read the ad previsit(v) postvisit(v) Figure 3.6 shows the outcome of depth-first search on a 12-node gra and pre[v] whenever = clock you arrive ing tiesat alphabetically any junction post[v] (ignore (vertex) the = pairs clock there of numbers are a variety for theof time passages being). can follow. careless calls choice explore of passages three times, might on, lead, and you finally around F. ins circles a result, or there mig toclock++ overlook some accessible rooted at part one of of these starting clock++ maze. points. learly, Together you need theyto constitute record asome foresti information during exploration onnectivity in undirected graphs Property This classic challenge has amused people for centuries. verybody knows need to explore a labyrinth n undirected is a ball graph of string is connected and aif piece there of is achalk. path between The chalk anyprev pair For any two vertices u and v, the intervals [pre[u], post[u]] and by marking the junctions of Figure you 3.6have is notalready connectedvisited. because, The for instance, string always there is no takes pathyou fro starting [pre[v], post[v]] place, enabling aredoes either have three disjoint connected regions, corresponding to the follow youdisjoint, to return or one to passages is contained that entirely you previously within saw but investigate. another. {,,, I, J} {,,, H,, } {F } How can we simulate these two primitives, chalk and string, on a computer marks are easy: for each vertex, maintain a oolean variable 92 indicating whethe 8 / 30 visited already. s for the ball of string, the correct cyberanalog is a stack. fter role of the string is to offer two primitive operations unwind to get to a new j
3 FS of irected raph Tree edges are actually part of the FS forest. ure 3.7 FS on a directed graph. Forward edges lead from a node to a nonchild descendant in the FS tree. 1,16 ack edges lead to an ancestor in the FS tree. 2,11 12,15 ross edges lead to neither descendant nor ancestor; they therefore F lead to a node that has already 3,10 beencompletely 13,14 explored (that is, already postvisited). F H You can ross confirm each of these characterizations by consulting the diagram of 4,7 8,9 you see why no other orderings are possible? H No cross edges in undirected graphs! 5, irected acyclic graphs Figure 3.7 has two forward edges, two back edges, and two cross edges. an you ack spotand them? forward edges merge cycle in a directed graph is a circular path v0 v1 v2 vk v0. 9 / 30 quite a few of them, for example, F. graph without10 / cycles 30 is ncestor and descendant relationships, as well as edge types, can outbe we can read testoff fordirectly acyclicity in linear time, with a single depth-first search. procedure postvisit(v) post[v] = from clock pre and post numbers. ecause of the depth-first exploration strategy, vertex u is an clock = clock ancestor + 1 of vertex v exactly in those cases where u is discovered first and v is discovered 95 during explore(u). This is to say pre(u) < pre(v) < post(v) < post(u), which we can iconnectivity depict pictorially in Undirected as two nestedraphs intervals: Illustration of iconnected omponents se timings will soon take on larger significance. Meanwhile, you might have noticed from ure 3.4 that: perty For any nodes u and v, the two intervals [pre(u), upost(u)] v and [pre(v), v post(v)] u are er disjoint efinition or one is (iconnected contained within omponents) the other. The case of descendants is symmetric, since u is a descendant of v if and only if v is an ancestor Why? ecause n [pre(u), post(u)] is essentially the time during which vertex u was on the articulation of u. point nd in since a graph edge is any categories vertex a are that based lies on entirely every on ancestor-descendant relationships, k. The last-in, first-out behavior of a stack explains the rest. path it from follows between thatvertices they, too, v, w. can be read off from pre and post numbers. Here is a summary of epth-first biconnected the various search graph possibilities in contains directed nofor articulation an graphs edge points. (u, v): FS The andcase dge of descendants Types is symmetric, since u is a descendant of v if and on cestor of u. nd since edge categories are based entirely on ancestor-descendan it follows that they, too, can be read off from pre and post numbers. Here i FS tree the various possibilities for an edge (u, v): pre/post ordering for (u, v) dge type.1 biconnected component of a graph Types of edges pre/post is a maximal ordering subgraph for (u, that v) dge type is biconnected. depth-first search algorithm can be run verbatim on directed graphs, taking care Tree/forward to trase edges only in their prescribed directions. Figure u 3.7 vshows anv example u and the search that results when vertices are considered in lexicographic order. In further analyzing the directed case, it helps to have terminology for important relationsbetween nodes of a tree. istheroot of the search v tree; u everythingelseisitsdescendant. u v ack ach biconnected component given a different color rticulation points have multiple colors ilarly, has descendants F,, and H, and conversely, is an ancestor of these three 11 / 30 nodes. family analogy is carried further: is the parent of, which is its child. ross ack Tree Forward u v v u u v v u v u u v v v u u Tree/forward ack ross 12 / 30
4 iconnected raphs Finding articulation points during FS iconnected components are not disjoint. rticulation points are duplicated across them. rticulation points single-points of failure raph is disconnected if any of them go down. etween any two u, v V in a biconnected graph there are two node-disjoint paths (and hence a cycle). uring FS visit of vertex v, we want to decide if it is an articulation point or not. ivide V into to disjoint sets: Vi includes nodes inside the FS tree rooted at v, and Vo = V Vi of nodes outside the FS tree rooted at v. Observation (1) Suppose that every inside node vi (i.e., vi Vi {v}) can reach some outside node vo (i.e., vo Vo) without going through v. Then v is not an articulation point. 13 / / 30 Finding articulation points during FS (2) Finding articulation points during FS (3) Proof: Paths within Vo: y properties of FS tree, any two vertices in Vo can reach each other without going through v Paths between vi and Vo: Once vi can reach any node in Vo, it can reach all other nodes in Vo without having to go through v. Paths within Vi: onsider nodes vi and v i in Vi {v}. y our assumption there is a path from vi to some vo Vo, and another path from v i to some v o Vo, neither involving v. onsider the path vi to vo to v o to v i, which does not pass through v. Thus, for every pair of vertices, there is a path between them that avoids v, and hence v is not an articulation point. 15 / 30 Observation (2) If Observation (1) does not hold then v is an articulation point. This means that there exists some vi that cannot reach an outside node vo without going through v. y definition, this means that v is an articulation point. 16 / 30
5 Finding articulation points during FS (3) Finding articulation points during FS (4) We combine and slightly strengthen Observations (1), (2), while omitting the proof, as it is essentially the same as before. Observation (3) et Y denote the set of ancestors of v and X its immediate children in the FS tree. Now, v is not an articulation point iff each x X has a path to some y Y without going through v. y focusing on just the children and ancestors of v, this makes it easier to decide on articulation points during FS. Note than any such path from x to y will follow zero or more tree edges down, followed by a back edge. Note than any such path from x to y will follow zero or more tree edges down, followed by a back edge. If this path bypasses v, this is going to occur due to a single back-edge that goes to an ancestor of v. So there is no need to consider paths with multiple back-edges. Note: Pre-number increases while following tree edges down, while it decreases when a back edge is followed. ey Idea: uring FS, for each vertex x, maintain the highest ancestor that can be reached from x by following tree edges down and then a back edge. 17 / / 30 Finding articulation points during FS (5) ey Idea: uring FS, maintain the highest ancestor reachable from x by following tree edges down and then a back edge. This info is maintained in the array low. low[x] low[x ] for every child x of x in FS tree. This captures the fact that we can follow the tree edge down from x to x, then go to whichever ancestor is reachable from x. lgorithmically, let low[x] = min(low[x], low[x ]) when explore(x ) returns low[x] pre[x ] for x adjacent to x but not a parent or child in the FS tree. lgorithmically, set low[x] = min(low[x], pre[x ]) y properties of FS, x is either a descendant or ancestor of x. s we are taking min, statement effective only if x is an ancestor. 19 / 30 Finding articulation points during FS (6) ey Idea: Maintain low during FS when visiting x, initialize low[x] to pre[x]. when a FS call on a child x of x returns, check if low[x ] pre[x]. If so, the highest ancestor x can reach is not higher than x, i.e., x cannot go to ancestors of x without going through x. So, mark x as articulation point If an adjacent vertex x is already visited when x considers it, set low[x] = min(low[x], pre[x ]) unless x is parent of x ll these can be done during a FS, while increasing the cost of each step by only a constant amount so, overall complexity is O( + V ) 20 / 30
6 irected cyclic raphs (s) Strongly onnected omponents (S) directed graph that contains no cycles. Often used to represent (acyclic) dependencies, partial orders,... Property (s and FS) directed graph has a cycle iff its FS reveals a back edge. In a dag, every edge leads to a vertex with lower post number. very dag has at least one source and one sink. nalog of connected components for undirected graphs efinition (S) Two vertices u and v in a directed graph are connected if there is a path from u to v and vice-versa. directed graph is strongly connected if any pair of vertices in the graph are connected. subgraph of a directed graph is said to be an S if it is a maximal subgraph that is strongly connected. Ss are also similar to biconnected components! 21 / / 30 FigureS 3.9 (a) xample directed graph and its strongly connected components. (b) The meta-graph. readth-first Search (FS) (a) (b) I J F H,,F,H,I J,, Traverse the graph by levels FS(v) visits v first Then it visits all immediate children of v then it visits children of children of v, and so on. s compared to FS, FS uses a queue (rather than a stack) to remember vertices that still need to be explored The textbook describes an algorithm for computing S in linear-time n efficient using algorithm FS. 23 / 30 The decomposition of a directed graph into its strongly connected components is very informative and useful. It turns out, fortunately, that it can be found in linear time by making 24 / 30
7 FS lgorithm bfs(v,, s) foreach u V do visited[u] = false q = {s}; visited[s] = true while q is nonempty do u = deque(q) foreach edge (u, v) do if not visited[v] then queue(q, v); visited[v] = true Shortest Paths and FS FS automatically computes shortest paths! bfs(v,, s) foreach u V do dist[u] = q = {s}; dist[s] = 0 while q is nonempty do u = deque(q) foreach edge (u, v) do if dist[v] = then queue(q, v); dist[v] = dist[u] + 1 ut not all paths are created equal! We would like to compute shortest weighted path a topic of future lecture. Figure 4.2 physical model of a graph. FS lgorithm Illustration S Figure 4.4 The result of breadth-first search on the graph of Figure 4.1. Order Queue contents of visitation after processing node Figure 4.3 readth-first search. S [S] procedure bfs(, S s) [ ] Input: raph = (V, ), [ directed ] or undirected; vertex s V [ ] Output: For all vertices u reachable from s, dist(u) is set [ ] to the distance [] from s to u. [ ] for all u V : 25 / / 30 dist(u) = right thing. If S is the starting point and the nodes are ordered alphabetically, they get visited dist(s) = 0 in the sequence shown in Figure 4.4. The breadth-first search tree, on the right, contains the edges Intro FS through iconnectivity which seach S FS node Paths isand initially Matrices discovered. Unlike the FS tree we saw earlier, it Q = [s] (queue containing just s) has the property that all its paths from S are the shortest possible. It is therefore a shortestpath nottree. empty: while Q is raph paths and oolean Matrices u = eject(q) for all orrectness edges (u, v) and efficiency : if dist(v) We have= developed : the basic intuition behind breadth-first search. In order to check that inject(q, the algorithm v) works correctly, we need to make sure that it faithfully executes this intuition. dist(v) What graph we= expect, dist(u) and precisely, its boolean + 1 is that matrix representation For each d = 0, 1, 2,..., there is a moment at which (1) all nodes at distance d from s have their distances correctly set; (2) all other nodes have their distances set to ; and (3) the queue contains exactly the nodes at distance d readth-first This has been phrased search with an inductive argument in mind. We have already discussed both the base case and the inductive step. an you fill in the details? In Figure 4.2, the lifting of s partitions the graph into layers: = s itself, the nodes at dis The overall running time of this algorithm is linear, O( V + 0 ), 0 0for 1exactly the same 1 from it, the nodes reasons at as depth-first distancesearch. 2 fromach it, vertex and so is put on. on the convenient queue exactly 0 way 0once, 0 towhen 0 compute it is first dist encountered, vertices so thereis are to2 proceed V queue operations. layer by layer. The restonce of the work we have is donepicked in the algorithm s from s to the other 4 out the n at distance 0, 1, innermost 2,..., d, loop. theover onesthe atcourse d + 1 of are execution, easily determined: this loop looks at they eachare edgeprecisely once (in directed the a graphs) or twice (in undirected graphs), and therefore takes O( ) time. unseen nodes that are adjacent to the layer at distance d. This suggests an iterative algo in which two layers Noware thatactive we have atboth anyfs given and time: FS before some us: layer how do d, their which exploration has been styles fully compare? ident and d + 1, which epth-first is being search discovered makes deep byincursions scanning intothe a graph, neighbors retreating of only layer when d. it runs out of new 27 / 30 nodes to visit. This strategy gives it the wonderful, subtle, and extremely useful28 properties / 30 readth-first search (FS) directly implements this simple reasoning (Figure 4.3) we saw in the hapter 3. ut it also means that FS can end up taking a long and convoluted tially the queue Q consists only of s, the one node at distance 0. nd for each subseq S
8 raph paths and oolean Matrices et be the adjacency matrix for a graph, and =. Now, ij = 1 iff there is path in the graph of length 2 from vi to vj et = +. Then ij = 1 iff there is path of length 2 between vi and vj efine = If = then ij = 1 iff vj is reachable from vi. = = = Shortest paths and Matrix Operations Redefine operations on matrix elements so that + becomes min, and becomes integer addition. = then ij = k iff the shortest path from vj to vi is of length k 29 / / 30
Depth-first search in undirected graphs What parts of the graph are reachable from a given vertex?
Why graphs? Chapter 3. Decompositions of graphs Awiderangeofproblemscanbeexpressedwithclarityandprecisionin the concise pictorial language of graphs. Graph coloring. Graph connectivity and reachability.
More informationAlgorithms (VII) Yijia Chen Shanghai Jiaotong University
Algorithms (VII) Yijia Chen Shanghai Jiaotong University Review of the Previous Lecture Depth-first search in undirected graphs Exploring graphs explore(g, v) Input: G = (V, E) is a graph; v V Output:
More informationAlgorithms (VII) Yijia Chen Shanghai Jiaotong University
Algorithms (VII) Yijia Chen Shanghai Jiaotong University Review of the Previous Lecture Depth-first search in undirected graphs Exploring graphs explore(g, v) Input: G = (V, E) is a graph; v V Output:
More informationCSC Intro to Intelligent Robotics, Spring Graphs
CSC 445 - Intro to Intelligent Robotics, Spring 2018 Graphs Graphs Definition: A graph G = (V, E) consists of a nonempty set V of vertices (or nodes) and a set E of edges. Each edge has either one or two
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 informationGraphs: Connectivity. A graph. Transportation systems. Social networks
graph raphs: onnectivity ordi ortadella and ordi Petit epartment of omputer Science Source: Wikipedia The network graph formed by Wikipedia editors (edges) contributing to different Wikipedia language
More informationGraphs: Connectivity. Jordi Cortadella and Jordi Petit Department of Computer Science
Graphs: Connectivity Jordi Cortadella and Jordi Petit Department of Computer Science A graph Source: Wikipedia The network graph formed by Wikipedia editors (edges) contributing to different Wikipedia
More informationDecompositions of graphs
hapter 3 ecompositions of graphs 3.1 Why graphs? wide range of problems can be expressed with clarity and precision in the concise pictorial language of graphs. or instance, consider the task of coloring
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 informationAlgorithms (V) Path in Graphs. Guoqiang Li. School of Software, Shanghai Jiao Tong University
Algorithms (V) Path in Graphs Guoqiang Li School of Software, Shanghai Jiao Tong University Review of the Previous Lecture Exploring Graphs EXPLORE(G, v) input : G = (V, E) is a graph; v V output: visited(u)
More informationDesign and Analysis of Algorithms
S 101, Winter 2018 esign and nalysis of lgorithms Lecture 3: onnected omponents lass URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ nd of Lecture 2: s, Topological Order irected cyclic raph.g., Vertices
More informationCSE 101. Algorithm Design and Analysis Miles Jones and Russell Impagliazzo Miles Office 4208 CSE Building
CSE 101 Algorithm Design and Analysis Miles Jones and Russell Impagliazzo mej016@eng.ucsd.edu russell@cs.ucsd.edu Miles Office 4208 CSE Building Russell s Office: 4248 CSE Building procedure DFS(G) cc
More informationAnalysis 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 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 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 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 informationCISC 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 informationDepth-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 informationModule 5 Graph Algorithms
Module 5 Graph lgorithms Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 97 E-mail: natarajan.meghanathan@jsums.edu 5. Graph Traversal lgorithms Depth First
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 informationThe guaranteed existence of a source suggests an alternative approach to linearization:
S. asgupta,.h. Papadimitriou, and U.V. Vazirani 101 Figure 3.8 directed acyclic graph with one source, two sinks, and four possible linearizations. F What types of dags can be linearized? Simple: ll of
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 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 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 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 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 informationDepth 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 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 informationElementary Graph Algorithms CSE 6331
Elementary Graph Algorithms CSE 6331 Reading Assignment: Chapter 22 1 Basic Depth-First Search Algorithm procedure Search(G = (V, E)) // Assume V = {1, 2,..., n} // // global array visited[1..n] // visited[1..n]
More information15-451/651: Design & Analysis of Algorithms October 5, 2017 Lecture #11: Depth First Search and Strong Components last changed: October 17, 2017
15-451/651: Design & Analysis of Algorithms October 5, 2017 Lecture #11: Depth First Search and Strong Components last changed: October 17, 2017 1 Introduction Depth first search is a very useful technique
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 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 informationCS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs
CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs 5 3 2 4 1 0 2 Graphs A graph G = (V, E) Where V is a set of vertices E is a set of edges connecting vertex pairs Example: V = {0, 1, 2, 3, 4, 5} E = {(0, 1),
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 informationCS483 Design and Analysis of Algorithms
CS483 Design and Analysis of Algorithms Lecture 9 Decompositions of Graphs Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: STII, Room 443, Friday 4:00pm - 6:00pm or by appointments
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 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 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 informationUNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items.
UNIT III TREES A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items. Tree: A tree is a finite set of one or more nodes such that, there
More informationINF2220: algorithms and data structures Series 7
Universitetet i Oslo nstitutt for nformatikk. Yu,. arabeg uiologo NF2220: algorithms and data structures Series 7 Topic ore on graphs: FS, iconnectivity, and strongly connected components (Exercises with
More 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 informationAdvanced Data Structures and Algorithms
dvanced ata Structures and lgorithms ssociate Professor r. Raed Ibraheem amed University of uman evelopment, College of Science and Technology Computer Science epartment 2015 2016 epartment of Computer
More informationGraphs: basic concepts and algorithms
: basic concepts and algorithms Topics covered by this lecture: - Reminder Trees Trees (in-order,post-order,pre-order) s (BFS, DFS) Denitions: Reminder Directed graph (digraph): G = (V, E), V - vertex
More informationUndirected 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 informationComputational Optimization ISE 407. Lecture 19. Dr. Ted Ralphs
Computational Optimization ISE 407 Lecture 19 Dr. Ted Ralphs ISE 407 Lecture 19 1 Search Algorithms Search algorithms are fundamental techniques applied to solve a wide range of optimization problems.
More informationIntroduction to Graphs. common/notes/ppt/
Introduction to Graphs http://people.cs.clemson.edu/~pargas/courses/cs212/ common/notes/ppt/ Introduction Graphs are a generalization of trees Nodes or verticies Edges or arcs Two kinds of graphs irected
More 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 informationCS 125 Section #5 Graph Traversal and Linear Programs October 6, 2016
CS 125 Section #5 Graph Traversal and Linear Programs October 6, 2016 1 Depth first search 1.1 The Algorithm Besides breadth first search, which we saw in class in relation to Dijkstra s algorithm, there
More informationDepth First Search (DFS)
Algorithms & Models of Computation CS/ECE 374, Fall 2017 Depth First Search (DFS) Lecture 16 Thursday, October 26, 2017 Sariel Har-Peled (UIUC) CS374 1 Fall 2017 1 / 60 Today Two topics: Structure of directed
More informationSearching 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 informationCS/COE
CS/COE 151 www.cs.pitt.edu/~lipschultz/cs151/ Graphs 5 3 2 4 1 Graphs A graph G = (V, E) Where V is a set of vertices E is a set of edges connecting vertex pairs Example: V = {, 1, 2, 3, 4, 5} E = {(,
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 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 informationUndirected Graphs. Hwansoo Han
Undirected Graphs Hwansoo Han Definitions Undirected graph (simply graph) G = (V, E) V : set of vertexes (vertices, nodes, points) E : set of edges (lines) An edge is an unordered pair Edge (v, w) = (w,
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 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 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 information4 Basics of Trees. Petr Hliněný, FI MU Brno 1 FI: MA010: Trees and Forests
4 Basics of Trees Trees, actually acyclic connected simple graphs, are among the simplest graph classes. Despite their simplicity, they still have rich structure and many useful application, such as in
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 informationHomework 2. Sample Solution. Due Date: Thursday, May 31, 11:59 pm
Homework Sample Solution Due Date: Thursday, May 31, 11:59 pm Directions: Your solutions should be typed and submitted as a single pdf on Gradescope by the due date. L A TEX is preferred but not required.
More informationL10 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 informationDEPTH-FIRST SEARCH A B C D E F G H I J K L M N O P. Graph Traversals. Depth-First Search
PTH-IRST SRH raph Traversals epth-irst Search H I J K L M N O P epth-irst Search 1 xploring a Labyrinth Without etting Lost depth-first search (S) in an undirected graph is like wandering in a labyrinth
More 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 informationDFS 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 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 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 informationGraph Search. Adnan Aziz
Graph Search Adnan Aziz Based on CLRS, Ch 22. Recall encountered graphs several weeks ago (CLRS B.4) restricted our attention to definitions, terminology, properties Now we ll see how to perform basic
More informationGRAPHICAL ALGORITHMS. UNIT _II Lecture-12 Slides No. 3-7 Lecture Slides No Lecture Slides No
GRAPHICAL ALGORITHMS UNIT _II Lecture-12 Slides No. 3-7 Lecture-13-16 Slides No. 8-26 Lecture-17-19 Slides No. 27-42 Topics Covered Graphs & Trees ( Some Basic Terminologies) Spanning Trees (BFS & DFS)
More informationThis course is intended for 3rd and/or 4th year undergraduate majors in Computer Science.
Lecture 9 Graphs This course is intended for 3rd and/or 4th year undergraduate majors in Computer Science. You need to be familiar with the design and use of basic data structures such as Lists, Stacks,
More informationCSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 5: SCC/BFS
CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.ucsd.edu Office 4208 CSE Building Lecture 5: SCC/BFS DECOMPOSITION There is a linear time algorithm that decomposes a directed graph into its
More informationDesign and Analysis of Algorithms
CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 6: BFS, SPs, Dijkstra Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Distance in a Graph The distance between two nodes is the length
More informationDFS & 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 informationApplications of BDF and DFS
January 14, 2016 1 Deciding whether a graph is bipartite using BFS. 2 Finding connected components of a graph (both BFS and DFS) works. 3 Deciding whether a digraph is strongly connected. 4 Finding cut
More informationDesign and Analysis of Algorithms
CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 6: BFS, SPs, Dijkstra Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Distance in a Graph The distance between two nodes is the length
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 THEORY. What are graphs? Why graphs? Graphs are usually used to represent different elements that are somehow related to each other.
GRPH THEORY Hadrian ng, Kyle See, March 2017 What are graphs? graph G is a pair G = (V, E) where V is a nonempty set of vertices and E is a set of edges e such that e = {a, b where a and b are vertices.
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 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 informationData Structures Lecture 14
Fall 2018 Fang Yu Software Security Lab. ept. Management Information Systems, National hengchi University ata Structures Lecture 14 Graphs efinition, Implementation and Traversal Graphs Formally speaking,
More informationU.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, Midterm 1 Solutions
U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, 2013 Midterm 1 Solutions 1 True/False 1. The Mayan base 20 system produces representations of size that is asymptotically
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 informationTutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].
Tutorial Question 1 A depth-first forest classifies the edges of a graph into tree, back, forward, and cross edges. A breadth-first tree can also be used to classify the edges reachable from the source
More informationLecture 9 Graph Traversal
Lecture 9 Graph Traversal Euiseong Seo (euiseong@skku.edu) SWE00: Principles in Programming Spring 0 Euiseong Seo (euiseong@skku.edu) Need for Graphs One of unifying themes of computer science Closely
More informationMAL 376: Graph Algorithms I Semester Lecture 1: July 24
MAL 376: Graph Algorithms I Semester 2014-2015 Lecture 1: July 24 Course Coordinator: Prof. B. S. Panda Scribes: Raghuvansh, Himanshu, Mohit, Abhishek Disclaimer: These notes have not been subjected to
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 information國立清華大學電機工程學系. Outline
國立清華大學電機工程學系 EE Data Structure Chapter Graph (Part I) Outline The Graph Abstract Data Type Introduction Definitions Graph Representations Elementary Graph Operations Minimum Cost Spanning Trees ch.- River
More informationFinding Strongly Connected Components
Yufei Tao ITEE University of Queensland We just can t get enough of the beautiful algorithm of DFS! In this lecture, we will use it to solve a problem finding strongly connected components that seems to
More 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 informationFigure 1: A directed graph.
1 Graphs A graph is a data structure that expresses relationships between objects. The objects are called nodes and the relationships are called edges. For example, social networks can be represented as
More informationCS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting
CS2 Algorithms and Data Structures Note 10 Depth-First Search and Topological Sorting In this lecture, we will analyse the running time of DFS and discuss a few applications. 10.1 A recursive implementation
More informationNote. Out of town Thursday afternoon. Willing to meet before 1pm, me if you want to meet then so I know to be in my office
raphs and Trees Note Out of town Thursday afternoon Willing to meet before pm, email me if you want to meet then so I know to be in my office few extra remarks about recursion If you can write it recursively
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 informationChapter 9: Elementary Graph Algorithms Basic Graph Concepts
hapter 9: Elementary Graph lgorithms asic Graph oncepts msc 250 Intro to lgorithms graph is a mathematical object that is used to model different situations objects and processes: Linked list Tree (partial
More informationUNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list
UNIT-4 Graph: Terminology, Representation, Traversals Applications - spanning trees, shortest path and Transitive closure, Topological sort. Sets: Representation - Operations on sets Applications. 1. Name
More information2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.
1. T F: Consider a directed graph G = (V, E) and a vertex s V. Suppose that for all v V, there exists a directed path in G from s to v. Suppose that a DFS is run on G, starting from s. Then, true or false:
More informationPractical 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 informationCS 561, Lecture 10. Jared Saia University of New Mexico
CS 561, Lecture 10 Jared Saia University of New Mexico Today s Outline The path that can be trodden is not the enduring and unchanging Path. The name that can be named is not the enduring and unchanging
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 informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
s of s Computer Science & Engineering 423/823 Design and Analysis of Lecture 03 (Chapter 22) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 29 s of s s are abstract data types that are applicable
More informationSpanning Trees. CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Motivation. Observations. Spanning tree via DFS
Spanning Trees S: ata Structures & lgorithms Lecture : Minimum Spanning Trees simple problem: iven a connected undirected graph =(V,), find a minimal subset of edges such that is still connected graph
More information