Analysis of Algorithms Prof. Karen Daniels
|
|
- Daniela Perry
- 5 years ago
- Views:
Transcription
1 UMass Lowell omputer Science 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]
2 Overview: raph lgorithms hapter 22: lementary raph lgorithms Introductory oncepts raph raversals: epth-irst Search readth-irst Search opological Sort Strongly onnected omponents (P figure) rief Introduction to Shortest Paths
3 hapter 22 raph lgorithms Introductory oncepts epth-irst Search readth-irst Search opological Sort [Source: ormen et al. textbook except where noted]
4 Introductory raph oncepts = (V,) Vertex egree Self-Loops dges may have weights (see hapters 23-24) Undirected raph No Self-Loops djacency is symmetric irected raph (digraph) egree: in/out Self-Loops allowed his treatment follows textbook ormen et al. Some definitions differ slightly from other graph literature.
5 Introductory raph oncepts: Motivation Networks are often modeled using graphs.
6 Introductory raph oncepts: Representations Undirected raph irected raph (digraph) djacency Matrix djacency List djacency Matrix djacency List his treatment follows textbook ormen et al. Some definitions differ slightly from other graph literature.
7 Introductory raph oncepts: Paths, ycles Path: length: number of edges simple: all vertices distinct ycle: irected raph: <v 0,v 1,...,v k > forms cycle if v 0 =v k and k>=1 simple cycle: v 1,v 2..,v k also distinct self-loop is cycle of length 1 Undirected raph: <v 0,v 1,...,v k > forms (simple) cycle if v 0 =v k and k>=3 simple cycle: v 1,v 2..,v k also distinct path <,,> simple cycle <,,,> simple cycle <,,,>= <,,,> his treatment follows textbook ormen et al. Some definitions differ slightly from other graph literature.
8 Introductory raph oncepts: onnectivity Undirected raph: connected every pair of vertices is connected by a path one connected component connected components: equivalence classes under is reachable from relation irected raph: strongly connected every pair of vertices is reachable from each other one strongly connected component strongly connected components: equivalence classes under mutually reachable relation maximal sized vertex subset inducing strongly connected subgraph not strongly connected connected 2 connected components strongly connected component his treatment follows textbook ormen et al. Some definitions differ slightly from other graph literature.
9 epth-irst Search (S) & readth-irst Search (S) xamples Vertex olor hanges dge lassification Using the Results of S & S Running ime nalysis
10 epth-irst Search (S)
11 xample: S of irected raph =(V,) dge lassification Legend: : tree edge : back edge : forward edge : cross edge djacency List: :,, :, : - :, :, :, :, Source: raph is from omputer lgorithms: Introduction to esign and nalysis by aase and elder.
12 S Pseudoode S() 1 for each vertex u V[] 2 do color[u] WHI 3 for each vertex u V[] 4 do if color[u] is WHI 5 then S_VISI(, u) S_VISI(, u) 1 color[u] RY 2 for each vertex v djlist[u] 3 do if color[v] is WHI 4 then S_VISI(,v) 5 color[u] LK see web handout for full details
13 Vertex olor hanges Vertex is WHI if it has not yet been encountered during the search. Vertex is RY if it has been encountered but has not yet been fully explored. Vertex is LK if it has been fully explored.
14 dge lassification ach edge of the original graph is classified during the search produces information needed to: build S or S spanning forest of trees detect cycles (S) or find shortest paths (S) When vertex u is being explored, edge e = (u,v) is classified based on the color of v when the edge is first explored: e is a tree edge if v is WHI [for S and S] e is a back edge if v is RY [for S only] for S this means v is an ancestor of u in the S tree e is a forward edge if v is LK and [for S only] v is a descendent of u in the S tree e is a cross edge if v is LK and [for S only] there is no ancestor or descendent relationship between u and v in the S tree Note that: or S we ll only consider tree edges. or S we consider all 4 edge types. In S of an undirected graph, every edge is either a tree edge or a back edge.
15 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
16 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
17 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
18 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
19 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
20 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
21 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
22 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
23 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
24 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
25 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
26 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
27 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
28 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
29 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
30 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
31 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
32 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
33 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
34 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
35 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
36 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
37 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
38 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
39 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
40 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
41 xample: (continued) S of irected raph djacency List: :,, :, : - :, :, :, :,
42 xample: (continued) S of irected raph xample: (continued) S of irected raph S ree 1 S ree 2
43 xample: S of Undirected raph =(V,) djacency List: :,,, :,, :,,,, :,,, :, :, :,
44 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
45 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
46 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
47 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
48 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
49 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
50 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
51 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
52 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
53 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
54 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
55 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
56 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
57 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
58 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
59 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
60 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
61 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
62 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
63 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
64 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
65 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
66 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
67 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
68 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :,
69 xample: (continued) S of Undirected raph xample: (continued) S of Undirected raph S ree
70 lementary raph lgorithms: S Review problem: RU or LS? he tree shown below on the right can be a S tree for some adjacency list representation of the graph shown below on the left. ack dge ree dge ree dge ree dge ree dge ross dge ree dge
71 readth-irst Search (S)
72 S Pseudoode See handout on web
73 xample: S of irected raph =(V,) dge lassification Legend: djacency List: :,, :, : - :, :, :, :, : tree edge only tree edges are used Source: raph is from omputer lgorithms: Introduction to esign and nalysis by aase and elder.
74 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue:
75 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue:
76 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue:
77 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue:
78 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue:
79 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue:
80 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue:
81 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue:
82 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue:
83 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue: -
84 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue:
85 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue:
86 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue:
87 xample: S of irected raph djacency List: :,, :, : - :, :, :, :, Queue: -
88 xample: (continued) S of irected raph Shortest path distance from : to = 1 to = 1 to = 1 to = 2 S ree 1 Shortest path distance from : to = 1 S ree 2
89 xample: S of Undirected raph =(V,) dge lassification Legend: : tree edge only tree edges are used djacency List: :,,, :,, :,,,, :,,, :, :, :,
90 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue:
91 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue:
92 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue:
93 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue:
94 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue:
95 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue:
96 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue:
97 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue:
98 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue:
99 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue:
100 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue:
101 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue:
102 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue:
103 xample: S of Undirected raph djacency List: :,,, :,, :,,,, :,,, :, :, :, Queue: -
104 xample: (continued) S of Undirected raph Shortest path distance from : to = 1 to = 2 to = 1 to = 2 to = 1 to = 1 S ree
105 epth-irst Search (S) & readth-irst Search (S) Using the Results of S & S Running ime nalysis
106 Using the Results of S & S Using S to etect ycles: directed graph is acyclic if and only if a epth-irst Search of yields no back edges. see p. 614 of text for proof Note: S can also be used to detect cycles in undirected graphs if notion of cycle is defined appropriately. S can also be used to identify strongly connected components in directed graphs and topologically sort. Using S for Shortest Paths: readth-irst Search of yields shortest path information: or each readth-irst Search tree, the path from its root u to a vertex v yields the shortest path from u to v in. see p of text for proof
107 lementary raph lgorithms: SRHIN: S, S for unweighted directed or undirected graph =(V,) ime: O( V + ) adj list O( V 2 ) adj matrix predecessor subgraph = forest of spanning trees readth-irst-search (S): Shortest Path istance rom source to each reachable vertex Record during traversal oundation of many shortest path algorithms Vertex color shows status: not yet encountered encountered, but not yet finished finished epth-irst-search (S): ncountering, finishing times well-formed nested (( )( ) ) structure S of undirected graph produces only back edges or tree edges irected graph is acyclic if and only if S yields no back edges See S, S Handout for Pseudoode
108 Running ime nalysis Key ideas in the analysis are similar for S and S. In both cases we assume an djacency List representation. Let s examine S. Let t be number of S trees generated by S Outer loop in S() executes t times each execution contains call: S_Visit(,u) each such call constructs a S tree by visiting (recursively) every node reachable from vertex u t ime: time to construct S tree i i 1 Now, let r i be the number of vertices in S tree i ime to construct S tree i: S() 1 for each vertex u V[] 2 do color[u] WHI 3 for each vertex u V[] 4 do if color[u] is WHI 5 then S_VISI(, u) S_VISI(, u) 1 color[u] RY 2 for each vertex v djlist[u] r i j 1 djlist [ jth vertex in S tree i] 3 do if color[v] is WHI 4 then S_VISI(,v) continued on next slide... 5 color[u] LK
109 otal S time: Running ime nalysis i t i 1 r j 1 djlist vertex S Now, consider this expression for the extreme values of t: if t=1, all edges are in one S tree and the expression simplifies to O( ) if t= V, each vertex is its own (degenerate) S tree with no edges so the expression simplifies to O( V ) O( V + ) is therefore an upper bound on the time for the extreme cases or values of t in between 1 and V we have these contributions to running time: 1 for each vertex that is its own (degenerate) S tree with no edges upper bound on this total is O( V ) djlist[u] for each vertex u that is a node of a non-degenerate S tree upper bound on this total is O( ) [ jth tree otal time for values of t in between 1 and V is therefore also O( V + ) otal time= O( V ) Note that for an djacency Matrix representation, we would need to scan an entire matrix row (containing V entries) each time we examined the vertices adjacent to a vertex. his would make the running time O( V 2 ) instead of O( V + ). in i]
110 opological Sort Source: Previous instructors
111 efinition: irected cyclic raph often abbreviated s used in many applications to indicate precedence among events. If S of a directed graph yields no back edges, then the graph contains no cycles [Lemma in text] his graph has more than one cycle. an you find them all? his graph has no cycles, so it is a.
112 efinition: opological Sort topological sort of a = (V, ) is a linear ordering of all its vertices such that if contains an edge (u, v), then u appears before v in the ordering. If the graph is not acyclic, then no linear ordering is possible. topological sort of a graph can be viewed as an ordering of its vertices along a horizontal line so that all directed edges go from left to right. opological sorting is thus different from the usual kind of "sorting".
113 lementary raph lgorithms: opological Sort for irected, cyclic raph () =(V,) OPOLOIL-SOR() 1 S() computes finishing times for each vertex 2 as each vertex is finished, insert it onto front of list 3 return list Produces linear ordering of vertices. or edge (u,v), u is ordered before v. source: textbook ormen et al.
114 opological Sort he following algorithm topologically sorts a : OPOLOIL-SOR() call S() to compute finishing times f[v] for each vertex v (this is equal to the order in which vertices change color from gray to black) as each vertex is finished (turns black), insert it onto the front of a linked list return the linked list of vertices
115 xample or this : S produces this result: this contains 2 S trees Vertices are blackened in the following order:,,,,,,
116 xample Vertices are added to front of a linked list in the blackening order. inal result is shown below Note that all tree edges and non-tree edges point to the right
117 opological Sort We can perform a topological sort in time (V + ), since depth-first search takes (V + ) time and it takes 0(1) time to insert each of the V vertices onto the front of the linked list.
118 opological Sort heorem 23.11: OPOLOIL-SOR() produces a topological sort of a directed acyclic graph. Proof: Suppose that S is run on a given dag = (V, ) to determine finishing times for its vertices. It suffices to show that for any pair of distinct vertices u,v Î V, if there is an edge in from u to v, then f[v] < f[u]. onsider any edge (u,v) explored by S(). When this edge is explored, v cannot be gray, since then v would be an ancestor of u and (u,v) would be a back edge, contradicting Lemma herefore, v must be either white or black. If v is white, it becomes a descendant of u, and so f[v] < f[u]. If v is black, then f[v] < f[u] as well. hus, for any edge (u,v) in the dag, we have f[v] < f[u], proving the theorem.
119 S as a asis for Shortest Path lgorithms for unweighted, undirected graph =(V,) S ime: O( V + ) adj list O( V 2 ) adj matrix Problem: iven 2 vertices u, v, find the shortest path in from u to v. Problem: iven a vertex u, find the shortest path in from u to each vertex. Source/Sink Shortest Path Single-Source Shortest Paths Solution: S starting at u. Stop at v. Solution: S starting at u. ull S tree. Problem: ind the shortest path in from each vertex u to each vertex v. ll-pairs Shortest Paths Solution: or each u: S starting at u; full S tree. ime: O( V ( V + )) adj list O( V 3 ) adj matrix source: based on Sedgewick, raph lgorithms
CISC 320 Introduction to Algorithms Fall Lecture 15 Depth First Search
IS 320 Introduction to lgorithms all 2014 Lecture 15 epth irst Search 1 Traversing raphs Systematic search of every edge and vertex of graph (directed or undirected) fficiency: each edge is visited no
More informationGraph Algorithms: Chapters Part 1: Introductory graph concepts
UMass Lowell Computer Science 91.503 Algorithms Dr. Haim Levkowitz Fall, 2007 Graph Algorithms: Chapters 22-25 Part 1: Introductory graph concepts 1 91.404 Graph Review Elementary Graph Algorithms Minimum
More 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 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 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 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 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 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 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 informationMinimum Spanning Trees Ch 23 Traversing graphs
Next: Graph Algorithms Graphs Ch 22 Graph representations adjacency list adjacency matrix Minimum Spanning Trees Ch 23 Traversing graphs Breadth-First Search Depth-First Search 11/30/17 CSE 3101 1 Graphs
More informationChapter 22. Elementary Graph Algorithms
Graph Algorithms - Spring 2011 Set 7. Lecturer: Huilan Chang Reference: (1) Cormen, Leiserson, Rivest, and Stein, Introduction to Algorithms, 2nd Edition, The MIT Press. (2) Lecture notes from C. Y. Chen
More 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 informationTaking Stock. IE170: Algorithms in Systems Engineering: Lecture 17. Depth-First Search. DFS (Initialize and Go) Last Time Depth-First Search
Taking Stock IE170: Algorithms in Systems Engineering: Lecture 17 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University March 2, 2007 Last Time Depth-First Search This Time:
More informationDesign and Analysis of Algorithms
Design and Analysis of Algorithms CS 5311 Lecture 19 Topological Sort Junzhou Huang, Ph.D. Department of Computer Science and ngineering CS5311 Design and Analysis of Algorithms 1 Topological Sort Want
More 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 informationRepresentations of Graphs
ELEMENTARY GRAPH ALGORITHMS -- CS-5321 Presentation -- I am Nishit Kapadia Representations of Graphs There are two standard ways: A collection of adjacency lists - they provide a compact way to represent
More informationDesign and Analysis of Algorithms
Design and Analysis of Algorithms CSE 5311 Lecture 18 Graph Algorithm Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 Graphs Graph G = (V,
More informationGraphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)
Graph Algorithms Graphs Graph G = (V, E) V = set of vertices E = set of edges (V V) Types of graphs Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.) Directed: (u, v) is edge from
More informationBasic Graph Algorithms
Basic Graph Algorithms 1 Representations of Graphs There are two standard ways to represent a graph G(V, E) where V is the set of vertices and E is the set of edges. adjacency list representation adjacency
More informationGraph representation
Graph Algorithms 1 Graph representation Given graph G = (V, E). May be either directed or undirected. Two common ways to represent for algorithms: 1. Adjacency lists. 2. Adjacency matrix. When expressing
More 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 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 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 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 informationElementary Graph Algorithms
Elementary Graph Algorithms Graphs Graph G = (V, E)» V = set of vertices» E = set of edges (V V) Types of graphs» Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.)» Directed: (u, v)
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 informationCHAPTER 23: ELEMENTARY GRAPH ALGORITHMS Representations of graphs
CHAPTER 23: ELEMENTARY GRAPH ALGORITHMS This chapter presents methods for representing a graph and for searching a graph. Searching a graph means systematically following the edges of the graph so as to
More informationECE 242 Data Structures and Algorithms. Graphs II. Lecture 27. Prof.
242 ata Structures and lgorithms http://www.ecs.umass.edu/~polizzi/teaching/242/ Graphs II Lecture 27 Prof. ric Polizzi Summary Previous Lecture omposed of vertices (nodes) and edges vertex or node edges
More 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 informationGraph ADT. Lecture18: Graph II. Adjacency Matrix. Representation of Graphs. Data Vertices and edges. Methods
Graph T S33: ata Structures (0) Lecture8: Graph II ohyung Han S, POSTH bhhan@postech.ac.kr ata Vertices and edges endvertices(e): an array of the two endvertices of e opposite(v,e): the vertex opposite
More 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 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 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 informationCOT 6405 Introduction to Theory of Algorithms
COT 6405 Introduction to Theory of Algorithms Topic 14. Graph Algorithms 11/7/2016 1 Elementary Graph Algorithms How to represent a graph? Adjacency lists Adjacency matrix How to search a graph? Breadth-first
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 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 informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 04 Elementary Graph Algorithms (Chapter 22) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu Introduction
More 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 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 informationTrees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006
Trees and Graphs Basic Definitions Tree: Any connected, acyclic graph G = (V,E) E = V -1 n-ary Tree: Tree s/t all vertices of degree n+1 A root has degree n Binary Search Tree: A binary tree such that
More informationCS 5114: Theory of Algorithms. Graph Algorithms. A Tree Proof. Graph Traversals. Clifford A. Shaffer. Spring 2014
epartment of omputer Science Virginia Tech lacksburg, Virginia opyright c 04 by lifford. Shaffer : Theory of lgorithms Title page : Theory of lgorithms lifford. Shaffer Spring 04 lifford. Shaffer epartment
More informationProof: if not f[u] < d[v], then u still grey while v is being visited. DFS visit(v) will then terminate before DFS visit(u).
Parenthesis property of DFS discovery and finishing times (Thm 23.6 of CLR): For any two nodes u,v of a directed graph, if d[u] < d[v] (i.e. u discovered before v), either f[v] < f[u] (i.e. visit time
More informationTCOM 501: Networking Theory & Fundamentals. Lecture 11 April 16, 2003 Prof. Yannis A. Korilis
TOM 50: Networking Theory & undamentals Lecture pril 6, 2003 Prof. Yannis. Korilis 2 Topics Routing in ata Network Graph Representation of a Network Undirected Graphs Spanning Trees and Minimum Weight
More 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 informationInf 2B: Graphs II - Applications of DFS
Inf 2B: Graphs II - Applications of DFS Kyriakos Kalorkoti School of Informatics University of Edinburgh Reminder: Recursive DFS Algorithm dfs(g) 1. Initialise Boolean array visited by setting all entries
More information22.3 Depth First Search
22.3 Depth First Search Depth-First Search(DFS) always visits a neighbour of the most recently visited vertex with an unvisited neighbour. This means the search moves forward when possible, and only backtracks
More informationDigraphs ( 12.4) Directed Graphs. Digraph Application. Digraph Properties. A digraph is a graph whose edges are all directed.
igraphs ( 12.4) irected Graphs OR OS digraph is a graph whose edges are all directed Short for directed graph pplications one- way streets flights task scheduling irected Graphs 1 irected Graphs 2 igraph
More informationProgramming Abstractions
Programming bstractions S 1 0 6 X ynthia ee Upcoming Topics raphs! 1. asics What are they? ow do we represent them? 2. Theorems What are some things we can prove about graphs? 3. readth-first search on
More informationBasic Graph Algorithms (CLRS B.4-B.5, )
Basic Graph Algorithms (CLRS B.-B.,.-.) Basic Graph Definitions A graph G = (V,E) consists of a finite set of vertices V and a finite set of edges E. Directed graphs: E is a set of ordered pairs of vertices
More informationIntroduction to Algorithms. Lecture 11
Introduction to Algorithms Lecture 11 Last Time Optimization Problems Greedy Algorithms Graph Representation & Algorithms Minimum Spanning Tree Prim s Algorithm Kruskal s Algorithm 2 Today s Topics Shortest
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 (VG ) v1 v n V(G) = V - Set of all vertices in G E(G) = E - Set of all edges (u,v) in G,
More informationApplications of BFS and DFS
pplications of S and S S all // : PM Some pplications of S and S S o find the shortest path from a vertex s to a vertex v in an unweighted graph o find the length of such a path o construct a S tree/forest
More informationBreadth First Search. Graph Traversal. CSE 2011 Winter Application examples. Two common graph traversal algorithms
Breadth irst Search CSE Winter Graph raversal Application examples Given a graph representation and a vertex s in the graph ind all paths from s to the other vertices wo common graph traversal algorithms
More 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 Spring 2010 s of s s are abstract data types that
More informationWhat are graphs? (Take 1)
Lecture 22: Let s Get Graphic Graph lgorithms Today s genda: What is a graph? Some graphs that you already know efinitions and Properties Implementing Graphs Topological Sort overed in hapter 9 of the
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 informationGraphs. Graphs. Representation of Graphs. CSE 680 Prof. Roger Crawfis. Two standard ways. Graph G = (V, E)» V = set of vertices
Introduction to Algorithms Graph Algorithms CSE 680 Prof. Roger Crawfis Partially from io.uwinnipeg.ca/~ychen2 Graphs Graph G = (V, E)» V = set of vertices» E = set of edges (V V) V) Types of graphs» Undirected:
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 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 informationData Structures and Algorithms. Chapter 7. Graphs
1 Data Structures and Algorithms Chapter 7 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples
More informationReading. Graph Terminology. Graphs. What are graphs? Varieties. Motivation for Graphs. Reading. CSE 373 Data Structures. Graphs are composed of.
Reading Graph Reading Goodrich and Tamassia, hapter 1 S 7 ata Structures What are graphs? Graphs Yes, this is a graph. Graphs are composed of Nodes (vertices) dges (arcs) node ut we are interested in a
More informationStrongly Connected Components
Strongly Connected Components Let G = (V, E) be a directed graph Write if there is a path from to in G Write if and is an equivalence relation: implies and implies s equivalence classes are called the
More 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 informationTaking Stock. IE170: Algorithms in Systems Engineering: Lecture 16. Graph Search Algorithms. Recall BFS
Taking Stock IE170: Algorithms in Systems Engineering: Lecture 16 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University February 28, 2007 Last Time The Wonderful World of This
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 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 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 informationCS1800: Graph Algorithms (2nd Part) Professor Kevin Gold
S1800: raph lgorithms (2nd Part) Professor Kevin old Summary So ar readth-irst Search (S) and epth-irst Search (S) are two efficient algorithms for finding paths on graphs. S also finds the shortest path.
More informationToday s Outline CSE 221: Algorithms and Data Structures Graphs (with no Axes to Grind)
Today s Outline S : lgorithms and ata Structures raphs (with no xes to rind) Steve Wolfman 0W Topological Sort: etting to Know raphs with a Sort raph T and raph Representations raph Terminology (a lot
More informationLesson 22: Basic Graph Concepts
Lesson 22: asic Graph oncepts msc 175 iscrete Mathematics 1. Introduction graph is a mathematical object that is used to model different relations between objects and processes: Linked list Flowchart of
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 informationGraph: representation and traversal
Graph: representation and traversal CISC5835, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Acknowledgement The set of slides have use materials from the following resources Slides for textbook
More informationCS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review
1 Review 1 Something I did not emphasize enough last time is that during the execution of depth-firstsearch, we construct depth-first-search trees. One graph may have multiple depth-firstsearch trees,
More informationReview: Graph Theory and Representation
Review: Graph Theory and Representation Graph Algorithms Graphs and Theorems about Graphs Graph implementation Graph Algorithms Shortest paths Minimum spanning tree What can graphs model? Cost of wiring
More informationGraphs: Definitions and Representations (Chapter 9)
oday s Outline Graphs: efinitions and Representations (hapter 9) dmin: HW #4 due hursday, Nov 10 at 11pm Memory hierarchy Graphs Representations SE 373 ata Structures and lgorithms 11/04/2011 1 11/04/2011
More informationGraphs. CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington
Graphs CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington 1 Representation Adjacency matrix??adjacency lists?? Review Graphs (from CSE 2315)
More 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 informationGraphs: Definitions and Representations (Chapter 9)
oday s Outline Graphs: efinitions and Representations (hapter 9) SE 373 ata Structures and lgorithms dmin: Homework #4 - due hurs, Nov 8 th at 11pm Midterm 2, ri Nov 16 Memory hierarchy Graphs Representations
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 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 informationWeek 5. 1 Analysing BFS. 2 Depth-first search. 3 Analysing DFS. 4 Dags and topological sorting. 5 Detecting cycles. CS 270 Algorithms.
1 2 Week 5 3 4 5 General remarks We finish, by analysing it. Then we consider the second main graph- algorithm, depth-first (). And we consider one application of, of graphs. Reading from CLRS for week
More informationProblem Set 2 Solutions
Design and Analysis of Algorithms February, 01 Massachusetts Institute of Technology 6.046J/18.410J Profs. Dana Moshkovitz and Bruce Tidor Handout 8 Problem Set Solutions This problem set is due at 9:00pm
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 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 informationCS 5114: Theory of Algorithms. Graph Algorithms. A Tree Proof. Graph Traversals. Clifford A. Shaffer. Spring 2014
epartment of omputer Science Virginia Tech lacksburg, Virginia opyright c 04 by lifford. Shaffer : Theory of lgorithms Title page : Theory of lgorithms lifford. Shaffer Spring 04 lifford. Shaffer epartment
More 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 informationData Struct. & Prob. Solving, M.C.Q. BANK, FOR UNIT 3, SECOND YEAR COMP. ENGG. SEM 1, 2012 PATTERN, U.O.P.
UNIT distribution for +1+1 + 1 + + = 11 (Only 1 will be asked for marks, s will be asked for 1 & s asked for marks ) Syllabus for Graphs Programmers perspective of graphs, Graph operations, storage structure,
More informationGraphs V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}
Graphs and Trees 1 Graphs (simple) graph G = (V, ) consists of V, a nonempty set of vertices and, a set of unordered pairs of distinct vertices called edges. xamples V={,,,,} ={ (,),(,),(,), (,),(,),(,)}
More informationAn Early Problem in Graph Theory. Clicker Question 1. Konigsberg and the River Pregel
raphs Topic " Hopefully, you've played around a bit with The Oracle of acon at Virginia and discovered how few steps are necessary to link just about anybody who has ever been in a movie to Kevin acon,
More informationUnit 2: Algorithmic Graph Theory
Unit 2: Algorithmic Graph Theory Course contents: Introduction to graph theory Basic graph algorithms Reading Chapter 3 Reference: Cormen, Leiserson, and Rivest, Introduction to Algorithms, 2 nd Ed., McGraw
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 informationTopic 12: Elementary Graph Algorithms
Topic 12: Elementary Graph Algorithms Pierre Flener Lars-enrik Eriksson (version of 2013-02-10) Different kinds of graphs List Tree A B C A B C Directed Acyclic Graph (DAG) D A B C D E Directed Graph (Digraph)
More informationGraphs. Terminology. Graphs & Breadth First Search (BFS) Extremely useful tool in modeling problems. Consist of: Vertices Edges
COMP Spring Graphs & BS / Slide Graphs Graphs & Breadth irst Search (BS) Extremely useful tool in modeling problems. Consist of: Vertices Edges Vertex A B D C E Edge Vertices can be considered sites or
More informationGraphs & Digraphs Tuesday, November 06, 2007
Graphs & Digraphs Tuesday, November 06, 2007 10:34 PM 16.1 Directed Graphs (digraphs) like a tree but w/ no root node & no guarantee of paths between nodes consists of: nodes/vertices - a set of elements
More 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 information(Re)Introduction to Graphs and Some Algorithms
(Re)Introduction to Graphs and Some Algorithms Graph Terminology (I) A graph is defined by a set of vertices V and a set of edges E. The edge set must work over the defined vertices in the vertex set.
More informationBreadth-First Search L 1 L Goodrich, Tamassia, Goldwasser Breadth-First Search 1
readth-irst Search 2013 Goodrich, Tamassia, Goldwasser readth-irst Search 1 readth-irst Search readth-first search (S) is a general technique for traversing a graph S traversal of a graph G Visits all
More informationBreadth First Search. cse2011 section 13.3 of textbook
Breadth irst Search cse section. of textbook Graph raversal (.) Application example Given a graph representation and a vertex s in the graph, find all paths from s to the other vertices. wo common graph
More informationDepth-First Search A B D E C
epth-first Search Outline and Reading efinitions (6.1) Subgraph onnectivity Spanning trees and forests epth-first search (6.3.1) lgorithm xample Properties nalysis pplications of FS (6.5) Path finding
More 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 information