Chapter 6. GRAPHS. Figure 6.1 : The bridges of Koenigsberg

Size: px
Start display at page:

Download "Chapter 6. GRAPHS. Figure 6.1 : The bridges of Koenigsberg"

Transcription

1 Chap : Graphs (Page ) Chapter. GRAPHS. THE GRAPH ABSTRACT DATA TYPE. ELEMENTARY GRAPH OPERATIONS. MINIMUM COST SPANNING TREES. SHORTEST PATHS AND TRANSITIVE CLOSURE. ACTIVITY NETWORKS Chap : Graphs (Page ) take bridge g to C take bridge d to A take bridge b to B take bridge f to D c C d g C c d e g A Kneiphof e D A D a b f B B f a b (a) (b) Figure. : The bridges of Koenigsberg

2 Chap : Graphs (Page ). The Graph Abstract Data Type A graph, G, consists of two sets: a finite, nonempty set of vertices, and a finite, possibly empty set of edges. V(G) and E(G) represent the sets of vertices and edges of G, respectively. Alternately, we may write G = (V, E) to represent a graph. Undirected graph is one in which the pair of vertices representing any edge is unordered. (v, v ), (v, v ) represent the same edge. Directed graph is one in which we represent each edge as a directed pair of vertices. <v, v > represents an edge in which v is the tail and v is the head. Chap : Graphs (Page ) Sample Graphs G G G V(G ) = {,,, } E(G ) = {(,), (,), (,), (,), (,), (,)} V(G ) = {,,,,,, } E(G ) = {(,), (,), (,), (,), (,), (,)} V(G ) = {,, } E(G ) = {<,>, <,>, <,>}

3 Chap : Graphs (Page ) Restriction on Graphs. A graph may not have an edge from a vertex, i, back to itself. self loops.. A graph may not have multiple occurrences of the same edge. if we allow, multigraph. Chap : Graphs (Page ) Definitions complete graph graph that has the maximum number of edges. adjacent, incident if (v, v ) is an edge in an undirected graph, then the vertices v and v are adjacent and the edge (v, v ) is incident on vertices v and v <v, v >: v is adjacent to v, while v is adjacent from v subgraph (Figure.) a subgraph of G is a graph G such that V(G ) Í V(G) and E(G ) Í E(G) path a path from vertex v p to vertex v q in a graph, G, is a sequence of vertices, v p, v i, v i,..., v in, v q such that (v p, v i ), (v i, vi ),..., (v in, v q ) are edges in an undirected graph.

4 Chap : Graphs (Page ) The length of a path is the number of edges on it. Simple (directed) path : path in which all vertices, except possibly the first and the last, are distinct. Cycle : simple path in which the first and the last vertices are the same. (Strongly) Connected In an undirected graph G, two vertices, v and v, are connected if there is a path in G from v to v. (Strongly) Connected Component : maximal connected subgraph Tree : graph that is connected and acyclic (it has no cycles). The degree of a vertex is the number of edges incident to the vertex. in-degree & out-degree digraph Chap : Graphs (Page 8) Graph Representations Adjacency Matrix The adjacency matrix of G is a two-dimensional n n array, say adj_mat. If the edge (v i, v j ) (<v i, v j > for a digraph) is in E(G), adj_mat[i][j] =. If there is no edge in E(G), adj_mat[i][j] =. ex) Undirected Graph: Symmetric Matrix

5 Chap : Graphs (Page 9) Adjacency Lists Replace the n rows of the adjacency matrix with n linked lists, one for each vertex in G. ex) headnodes vertex link null null null null null null null Chap : Graphs (Page ) Adjacency Multilists maintaining the lists as multilists, that is, lists in which nodes are shared among several lists, facilitates this operation. marked vertex vertex path path ex) headnodes The lists are: vertex : N -> N -> N vertex : N -> N -> N vertex : N -> N -> N vertex : N -> N -> N N N N N N N N null N N N N N null N N null null edge(, ) edge(, ) edge(, ) edge(, ) edge(, ) edge(, )

6 Chap : Graphs (Page ) Analysis of Graph Representations How many edges are there in G? or Is G connected? Adjacency Matrix: O(n ) time to search (n -n)/ Adjacency List: O(e+n) Good if e << n / (sparse graphs) Finding in-degree of a vertex in a digraph Adjacency Matrx: O(n) Adjacency List: O(e+n) maintaining two lists (original adjacency list & inverse adjacency list) using alternate node structure for adjacency list (Figure.) tail head column link for head row link for tail Chap : Graphs (Page ). Elementary Graph Operations. Depth First Search. Breadth First Search. Connected Components. Spanning Trees. Biconnected Components and Articulation Points

7 Chap : Graphs (Page ) Depth First Search Algorithm. begin the search by visiting the start vertex, v.. select an unvisited vertex, w, from v s adjacency list and carry out a depth first search on w. (using recursion) #define FALSE #define TRUE short int visited[max_vertices]; void dfs(int v) { node_pointer w; visited[v] = TRUE; printf( d, v); for (w = graph[v]; w; w = w->link) if (!visited[w->vertex]) dfs(w->vertex); } Chap : Graphs (Page ) ex) V V V V V V V V null null null null null null null null depth first search order : v, v, v, v, v, v, v, v

8 Chap : Graphs (Page ) Breadth First Search Algorithm. starts at vertex v and marks it as visited.. visits each of the vertices on v s adjacency list.. when we have visited all the vertices on v s adjacency list, we visit all the unvisited vertices that are adjacent to the first vertex on v s adjacency list (using queue). typedef struct queue *queue_pointer; typedef struct queue { int vertex; queue_pointer link; }; void addq(queue_pointer *, queue_pointer *, int); int deleteq(queue_pointer *); Chap : Graphs (Page ) void bfs(int v) { /* breadth first traversal of a graph, starting with node v the global array visited is initialized to, the queue */ node_pointer w; queue_pointer front =, rear = ; printf( %d, v); visited[v] = TRUE; addq(&front, &rear, v); while (front) { v = deleteq(&front); for (w = graph[v]; w; w = w->link) if (!visited[w->vertex]) { printf( %d, w->vertex); addq(&front,&rear,w->vertex); visited[w->vertex] = TRUE; } } }

9 Chap : Graphs (Page ) Connected Components whether or not an undirected graph is connected? calling either dfs() or bfs() and then determining if there are any unvisited vertices. listing the connected components of a graph. void connected (void) { /* determine the connected components of a graph */ int i for (i = ; i < n; i++) if (!visited[i]) { dfs(i); printf( n ); } } Chap : Graphs (Page 8) Spanning Trees A spanning tree is any tree that consists solely of edges in G and that includes all vertices in G. use either dfs or bfs to create a spanning tree. depth first spanning tree breadth first spanning tree V V V V V V V V V V V V V V V depth first spanning tree V breadth first spanning tree

10 Chap : Graphs (Page 9) Biconnected Components and Articulation Points Definition An articulation point is a vertex v of G such that the deletion of v, together with all edges incident on v, produces a graph, G that has at least two connected components. A biconnected graph is a connected graph that has no articulation points. A biconnected component of a connected undirected graph is a maximal biconnected subgraph, H, of G. The maximal biconnected subgraph means that G contains no other subgraph that is both biconnected and properly contains H. Chap : Graphs (Page ) ex) (a) Connected graph (b) Biconnected components Articulation point :,,,

11 Chap : Graphs (Page ) Finding Articulation Point Two Rules Root of a DFS tree is an articulation point iff it has at least two children. Any other vertex u is an articulation point iff it has at least one child w such that we cannot reach an ancestor of u using a path that consists of only w, descendants of w, and a single back edge (a) depth first spanning tree (b) Chap : Graphs (Page ) Minimum Cost Spanning Trees Definition cost of a spanning tree of a weighted undirected graph : the sum of the costs (weights) of the edges in the spanning tree Minimum cost spanning tree : a spanning tree of least cost Three algorithms for minimum cost spanning tree Kruskal s, Prim s, Sollin s algorithms All three use an greedy method. Constraints for minimum cost spanning tree algorithms. must use only edges within the graph.. must use exactly n- edges.. may not use edges that would produce a cycle.

12 Chap : Graphs (Page ) Kruskal s Algorithm Methods Builds a minimum cost tree T by adding edges to T one at a time. Selects the edges for inclusion in T in non-decreasing order of their cost. An edge is added in T if it does not form a cycle. Graph G is connected and has n > vertices, exactly n - edges will be selected Chap : Graphs (Page ) Kruskal s Algorithm (Cont d) T = {}; while ( T contains less than n- edges && E is not empty ) { choose a least cost edge (v,w) form E; delete (v,w) form E; if ((v,w) does not create a cycle in T) add (v,w) to T; else discard(v,w); } if ( T contains fewer than n- edges ) printf( No spanning tree\n );

13 Chap : Graphs (Page ) (Ex) Kruskal s Algorithm 8 8 (a) (b) (c) (d) (e) (f) Chap : Graphs (Page ) Discussion of Kruskal s Algorithm determine an edge with minimum cost edge maintain the edges in E as a sorted sequential : O(e log e) better method : use min heap finding the next cost edge : O(log e) construction of heap : O(e) Cycle checking use union-find operation Analysis union-find operations require less than choosing and deleting an edge, the latter operations determine the total computing time Total Computing Time : O(e log e)

14 Chap : Graphs (Page ) Theorem.: Let G be an undirected connected graph. Kruskal s algorithm generates a minimum cost spanning tree. proof) We shall show that a) Kruskal s method produces a spanning tree whenever a spanning tree exists. b) The spanning tree generated is of minimum cost. Chap : Graphs (Page 8) Prim s Algorithm Method: Complexity = O(n ) Constructs the minimum cost spanning tree one edge at a time. At each stage, the set of selected edges forms a tree. Begins with a tree, T, that contains a single vertex. Add a least cost edge (u,v) to T such that T {(u,v)} is also a tree.

15 Chap : Graphs (Page 9) Prim s Algorithm (Cont d) T = {}; TV = {}; /* start with vertex and no edges */ while ( T contains fewer than n- edges ) { let (u,v) be a least cost edge such that u TV and v TV; if (there is no such edge) break; add v to TV; add (u,v) to T; } if ( T contains fewer than n- edges ) printf( No spanning tree\n ); Chap : Graphs (Page ) (Ex) Prim s Algorithm 8 8 (a) (b) (c) (d) (e) (f)

16 Chap : Graphs (Page ) Sollin s Algorithm Methods Aelects several edges for inclusion in T at each stage. At the start of the stage, the selected edges, together with all n graph vertices, form a spanning forest. During a stage, select one edge for each tree in the forest. Since two trees in the forest could select the same edge, need to eliminate multiple copies of edges. At start of the first stage the set of selected edges is empty. Terminates when there is only tree at the end of a stage or no edges remain for selection. Chap : Graphs (Page ) (Ex) Sollin s Algorithm 8 8 (a) (b) (c) (d)

17 Chap : Graphs (Page ). Shortest paths and Transitive closure Problem. Is there a path from A to B?. If there is more than one path from A to B, which path is the shortest? Assume The length of a path is the sum of the weights of the edges on that path rather than the number of edges on the path. Since one-way streets are possible, the graphs are directed. Assume that all weights are positive. Chap : Graphs (Page ) Single Source All Destinations Problem ex) a directed graph, G = (V, E), a weighting function, w(e), w(e) >, for the edges of G, and a source vertex, v. Determine a shortest path from v to each of the remaining vertices of G. V V V V V V path length v v v v v v v v v v v

18 Chap : Graphs (Page ) Greedy algorithm Notation S : the set of vertices, including v, whose shortest paths have been found. For w not in S, let distance[w] be the length of the shortest path starting from v, going through vertices only in S, and ending in w. Observations. If the next shortest path is to vertex u, then the path from v to u goes through only those vertices that are in S.. Vertex u is chosen so that it has the minimum distance, distance[u], among all the vertices not in S. (from the definition of distance and observation.). Once we have selected u and generated the shortest path from v to u, u becomes a member of S. Adding u to S can change the distance[w](w S). If the distance changes, the length of the shorter path is distance[u] + length(<u,w>). Chap : Graphs (Page ) Dijkstra s algorithm Implement Dijkstra s algorithm Assume that the n vertices are numbered from to n- Maintain the set S as an array, found, with found[i] = FALSE if vertex i is not in S and found[i] = TRUE if vertex i is in S. Represent the graph by its cost adjacency matrix, with cost[i][j] being the weight of edge <i, j> If the edge <i, j> is not in G, we set cost[i][j] to some large number the number must be larger than any of the values in the cost matrix. the number must be chosen so that the statement distance[u] + cost[u][w] does not produce an overflow into the sign bit.

19 Chap : Graphs (Page ) #define MAX_VERTICES int cost[][max_vertices] = {{,,,,, }, {,,,,, }, {,,,,, }, {,,,,, }, {,,,,, }, {,,,,, }}; int distance[max_vertices], n = MAX_VERTICES; short int found[max_vertices]; int choose(int distance[], int n, short int found[]) { /* find the smallest distance not yet checked */ int i, min, minpos; min = INT_MAX; minpos = -; for (i = ; i < n; i++) if (distance[i] < min &&!found[i]) { min = distance[i]; minpos = i; } return minpos; } Chap : Graphs (Page 8) void shortestpath(int v, int cost[][max_vertices], int distance[], int n, short int found[]) { /* Implement Dijkstra s Algorithm */ int i, u, w; for (i = ; i < n; i++) { found[i] = FALSE; distance[i] = cost[v][i]; } Complexity = found[v] = TRUE; distance[v] = ; for (i = ; i < n - ; i++) { u = choose(distance, n, found); found[u] = TRUE; for (w = ; w < n; w++) if (!found[w]) if (distance[u] + cost[u][w] < distance[w]) distance[w] = distance[u] + cost[u][w]; } }

20 Chap : Graphs (Page 9) San Frnacisco Los Angeles 8 Denver Boston Chicago NewYork 9 (a) Digraph of hypothetical airline routes New Orleans Miami 8 9 Figure. : Digraph of airline routes (b) Cost adjacency matrix Chap : Graphs (Page ) Distance Iteration S Vertax selected LA [] SF [] DEN [] CHI [] BOST [] NY [] MIA [] NO [] Initial { } {,} {,,} + + {,,,} + {,,,,} {,,,,,} {,,,,,,} Figure. : Action of shortestpath on the digraph of Figure.

21 Chap : Graphs (Page ) All Pairs Shortest Paths Problem find the shortest paths between all pairs of vertices, v i, v j, i j. Solution. using shortestpath with each of the vertices in V(G) as the source : O(n ).. Dynamic programming method : O(n ) with a smaller constant factor. Chap : Graphs (Page ) Dynamic programming algorithm A k [i][j] : cost of the shortest path from i to j, using only those intermediate vertices with an index k. cost of the shortest path from i to j is A n- [i][j]. A - [i][j] = cost[i][j]. successively generate the matrices A, A, A,..., A n-. Calculate A k with A k-. the shortest path does not go through vertex k : A k [i][j] = A k- [i][j].. the shortest path does go through vertex k : A k [i][j] = A k- [i][k] + A k- [k][j]. A k [i][j] = min {A k- [i][j], A k [i][j] = A k- [i][k] + A k- [k][j] }, k. A - [i][j] = cost[i][j].

22 Chap : Graphs (Page ) void allcosts (int cost[ ] [MAX_VERTICES], int distance[] [MAX_VERTICES], int n) { /* determine the distance from each vertex to every other vertex, cost is the adjacency matrix, distance is the matrix of distances */ int i, j, k; for (i = ; i < n; i++) for (j = ; j < n; j++) distance[i][j] = cost[i][j]; for (k = ; k < n; k++) for (i = ; i < n; i++) for (j = ; j < n; j++) if (distance[i][k] + distance[k][j] < distance[i][j]) distance[i][j] = distance[i][k] + distance[k][j]; } Program. : All pairs, shortest paths function Chap : Graphs (Page ) A - A V V V A A Figure. : Matrix A k produced by allcosts for Figure.(a)

23 Chap : Graphs (Page ) Transitive Closure transitive closure matrix Denoted A +, of a directed graph, G, is a matrix such A + [i][j] = if there is a path of length > from i to j; otherwise, A + [i][j] =. reflexive transitive closure matrix Denoted A *, of a directed graph, G, is a matrix such that A * [i][j] = if there is a path of length from i to j; otherwise, A * [i][j] =. Program: Change allcosts distance[i][j] = distance[i][j] distance[i][k] && distance[k][j] Chap : Graphs (Page ) ex) transitive closure Digraph G Adjacent matrix A for G A + A *

24 Chap : Graphs (Page ). Activity Networks Activity Subproject (divide and conquer) The entire project is successfully completed when each of the activities is completed Two Networks Activity on Vertex (AOV) Networks Activity on Edge (AOE) Networks Chap : Graphs (Page 8) AOV Network Definitions: AOV Network: Digraph G (vertex = activities, edge = precedence relation) Predecessor (Successor): direct path from i to j Immediate Predecessor (Successor): <i, j> Partial Order: precedence relation that is both transitive and irreflexive Topological Order: linear ordering of vertices with precedence relation Problems How can we find out an algorithm that sorts the tasks into topological order? Topological Sort

25 Chap : Graphs (Page 9) Course number C C C C C C C C8 C9 C C C C C C Course name Programming I Discrete Mathematics Data Structures Calculus I Calculus II Linear Algebra Analysis of Algorithms Assembly Languages Operating Systems Programming Languages Compiler Design Artificial Intelligence Computational Theory Parallel Algorithms Numerical Analysis Prerequisites None None C, C None C C C, C C C, C8 C C C C C C (a) Courses needed for a computer science degree at a hypothetical university C C C C C C8 C C C C9 C C C (b) AOV network representing courses as vertices and edges as prerequisites Figure.8 : An AOV network C C Chap : Graphs (Page ) for ( i = ; i < n; i++) { if every vertex has a predecessor { fprintf (stderr, Network has a cycle.\n ); exit (); } pick a vertex v that has no predecessors; output v; delete v and all edges leading out of v from the network; } Program. : Topological sort

26 Chap : Graphs (Page ) V V V V V V V V V V V V V V V (a) initial (b) V (c) V V V V V V V (d) V (e) V (f) V (g) V Topological order generated : V, V, V, V, V, V Figure.9 : Simulation of Program. on an AOV network Chap : Graphs (Page ) Representation of AOV Network Determine if a vertex has any predecessors Keep a count of # of immediate predecessors for each vertex Delete a vertex and all of its incident edges Represent the network by its adjacency lists Declarations typedef struct node *node_pointer; typedef struct node { int vertex; node_pointer link; }; typedef struct { int count; node_pointer link; } hdnodes; hdnode graph[max_vertices]; v v v v v v count link Null Null Null Null Null Null

27 Chap : Graphs (Page ) void topsort(hdnodes graph[], int n) { int i, j, k, top; node_pointer ptr; /* PredecessorÈ Ž\ vertex stack ù */ top = -; for (i = ; i < n; i++) if (!graph[i].count) { graph[i].count = top; top = i; } for (i = ; i < n; i++) if (top == -) { fprintf(stderr, Network has a cycle.\n ); exit(); } else { j = top; /* Stack ä ä8 */ top = graph[top].count; printf( v%d,, j); for (ptr = graph[j].link; ptr; ptr = ptr->link) { /* Successor vertex count ØT */ k = ptr->vertex; graph[k].count--; if (!graph[k].count) { /* $ vertexd stack M */ graph[k].count = top; top = k; } } } } Chap : Graphs (Page ) Activity on Edge (AOE) Network Representation Edge: Activity Vertex: Event occurs when all incoming activities have been completed start v a = a = a = v v v a = v a = a = v a = 9 a = v v a 8 = a 9 = v 8 a = finish event v v v v v8 interpretation start of project completion of activity a completion of activity a and a completion of activity a and a8 completion of project (b) Interpretation of some of the events in the activity graph of (a) (a) AOE Network. Activity graph of a hypothetical project

28 Chap : Graphs (Page ) Critical Path of AOE Network Critical Path A path that has the longest length from start vertex to finish vertex Result in bottlenecks Earliest Time of an event v i Length of the longest path from start vertex v to v i (earliest() = ) earliest(v i ) Earliest start time for all outgoing activities of v i (early() = ) Latest Time, late(i), of activity a i Latest time the activity may start without increasing the project duration early() = & late() = 8, early() = & late() = Critical Activity Activity for which early(i) = late(i) Chap : Graphs (Page ) Calculation of Earliest Times Suppose activity a i is represented by edge <k, l> early(i) = earliest[k] late(i) = latest[l] - duration of activity a i Computing earliest[j] forward scan the network using topsort algorithm earliest[] = earliest[j] = max{earliest[i] + duration of <i, j>} for i P(j), where P(j) is the set of immediate predecessors of j Insert the following statement at the end of the else clause in topsort if (earliest[k] < earliest[j] + ptr->duration) earliest[k] = earliest[j] + ptr->duration

29 Chap : Graphs (Page ) count link vertex dur link V V V V V 9 V V 8 V 8 V 8 (a) Adjacency lists for Figure.(a) Chap : Graphs (Page 8) Earliest [] [] [] [] [] [] [] [] [8] Stack initial [] output V [,, ] output V [,, ] output V [, ] output V [] output V [] output V [, ] output V [] output V 8 [8] output V 8 (b) Computation of earliest Figure. : Computing earliest from topological sort

30 Chap : Graphs (Page 9) Calculation of Latest Times Computing latest[j] backward scan the network using topsort algorithm latest[n-] = earliest[n-] latest[j] = min{latest[i] - duration of <j, i>} for i S(j), where S(j) is the set of immediate successors of j Using inverse adjacence list Insert the following statement at the end of the else clause in topsort if (latest[k]> latest[j] - ptr->duration) latest[k] = latest[j] - ptr->duration Chap : Graphs (Page ) count link vertex dur link V V V V V V V 9 V V 8 (a) Inverted adjacency lists for AOE network of Figure.(a)

31 Chap : Graphs (Page ) Earliest [] [] [] [] [] [] [] [] [8] Stack initial [8] output V [, ] output V [, ] output V [, ] output V [] output V [] output V 8 8 [, ] output V 8 8 [] output V 8 8 [] (b) Computation of latest Figure. : Computing latest for AOE network of Figure.(a) Chap : Graphs (Page ) Calculation of Early(i) & Late(i) of a i Suppose activity a i is represented by edge <k, l> early(i) = earliest[k] late(i) = latest[l] - duration of activity a i Activity Early Late Late - Early Critical a a a a a a a a a 8 a 9 a 8 Yes No No Yes No No Yes Yes No Yes Yes

Konigsberg Bridge Problem

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

More information

國立清華大學電機工程學系. Outline

國立清華大學電機工程學系. 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 information

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies: UNIT 5 CSE 103 - Unit V- Graph GRAPH Graph is another important non-linear data structure. In tree Structure, there is a hierarchical relationship between, parent and children that is one-to-many relationship.

More information

Outline. Introduction. Representations of Graphs Graph Traversals. Applications. Definitions and Basic Terminologies

Outline. Introduction. Representations of Graphs Graph Traversals. Applications. Definitions and Basic Terminologies Graph Chapter 9 Outline Introduction Definitions and Basic Terminologies Representations of Graphs Graph Traversals Breadth first traversal Depth first traversal Applications Single source shortest path

More information

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

UNIT 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 information

Undirected Graphs. Hwansoo Han

Undirected 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 information

Chapter 9 Graph Algorithms

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

More information

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

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

More information

Basic Graph Definitions

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

More information

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

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

More information

GRAPHICAL 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 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 information

Elementary Graph Algorithms CSE 6331

Elementary 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 information

Chapter 9 Graph Algorithms

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

More information

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms Introduction graph theory useful in practice represent many real-life problems can be if not careful with data structures Chapter 9 Graph s 2 Definitions Definitions an undirected graph is a finite set

More information

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value 1 Possible implementations Sorted linear implementations o Appropriate if

More information

Review of Data Structure(I)

Review of Data Structure(I) Review of Data Structure(I) Ch. Basic Concepts: Pointers and dynamic memory allocation, data abstraction, algorithm specification, performance analysis & measurement Ch. Arrays and Structures: Dynamically

More information

Graph Algorithms Using Depth First Search

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

More information

Graph Traversals. CS200 - Graphs 1

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

More information

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

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

More information

UNIT 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. 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 information

CS302 - Data Structures using C++

CS302 - Data Structures using C++ CS302 - Data Structures using C++ Topic: Graphs - Introduction Kostas Alexis Terminology In the context of our course, graphs represent relations among data items G = {V,E} A graph is a set of vertices

More information

Graph. Vertex. edge. Directed Graph. Undirected Graph

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

More information

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

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

More information

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE A6-R3: DATA STRUCTURE THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered in the TEAR-OFF

More information

Graphs & Digraphs Tuesday, November 06, 2007

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

More information

ROOT A node which doesn t have a parent. In the above tree. The Root is A. LEAF A node which doesn t have children is called leaf or Terminal node.

ROOT A node which doesn t have a parent. In the above tree. The Root is A. LEAF A node which doesn t have children is called leaf or Terminal node. UNIT III : DYNAMIC STORAGE MANAGEMENT Trees: Binary tree, Terminology, Representation, Traversals, Applications. Graph: Terminology, Representation, Traversals Applications - spanning trees, shortest path.

More information

Algorithm Design and Analysis

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

More information

Minimum Spanning Trees Ch 23 Traversing graphs

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

More information

COT 6405 Introduction to Theory of Algorithms

COT 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 information

ROOT: A node which doesn't have a parent. In the above tree. The Root is A.

ROOT: A node which doesn't have a parent. In the above tree. The Root is A. TREE: A tree is a finite set of one or more nodes such that there is a specially designated node called the Root, and zero or more non empty sub trees T 1, T 2...T k, each of whose roots are connected

More information

CSCE 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 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 information

Graphs. Undirected edge has no orientation (u,v). u v. Undirected graph => no oriented edge. Directed graph => every edge has an orientation.

Graphs. Undirected edge has no orientation (u,v). u v. Undirected graph => no oriented edge. Directed graph => every edge has an orientation. Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects two different vertices. Edges are also called arcs and lines. Directed edge has an

More information

Graph Representation

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

More information

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY

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

More information

Algorithm Design (8) Graph Algorithms 1/2

Algorithm Design (8) Graph Algorithms 1/2 Graph Algorithm Design (8) Graph Algorithms / Graph:, : A finite set of vertices (or nodes) : A finite set of edges (or arcs or branches) each of which connect two vertices Takashi Chikayama School of

More information

CS521 \ Notes for the Final Exam

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

More information

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI. Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI. Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II Anna University 2 & 16 Mark Questions & Answers Year / Semester: II / III

More information

CS 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 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 information

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths Part VI Graph algorithms Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths 1 Chapter 22 Elementary Graph Algorithms Representations of graphs

More information

W4231: Analysis of Algorithms

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

More information

Unweighted Graphs & Algorithms

Unweighted Graphs & Algorithms Unweighted Graphs & Algorithms Zachary Friggstad Programming Club Meeting References Chapter 4: Graph (Section 4.2) Chapter 22: Elementary Graph Algorithms Graphs Features: vertices/nodes/dots and edges/links/lines

More information

1. Graph and Representation

1. Graph and Representation Chapter Graphs Tree Root Direction: parent-child relationships No cycles Graph Vertices + Edges No tree restrictions Examples World Wide Web Maps. Graph and Representation A graph G: a pair (V, E) vertices

More information

Foundations of Discrete Mathematics

Foundations of Discrete Mathematics Foundations of Discrete Mathematics Chapter 12 By Dr. Dalia M. Gil, Ph.D. Trees Tree are useful in computer science, where they are employed in a wide range of algorithms. They are used to construct efficient

More information

2. 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.

2. 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 information

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F)) DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES UNIT IV NONLINEAR DATA STRUCTURES Part A 1. Define Tree [N/D 08]

More information

Graph and Digraph Glossary

Graph and Digraph Glossary 1 of 15 31.1.2004 14:45 Graph and Digraph Glossary A B C D E F G H I-J K L M N O P-Q R S T U V W-Z Acyclic Graph A graph is acyclic if it contains no cycles. Adjacency Matrix A 0-1 square matrix whose

More information

GRAPHS Lecture 17 CS2110 Spring 2014

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

More information

Graph Algorithms. Definition

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

More information

Applications of BDF and DFS

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

More information

Minimum-Cost Spanning Tree. Example

Minimum-Cost Spanning Tree. Example Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum cost Example 2 4 12 6 3 Network has 10 edges.

More information

Example. Minimum-Cost Spanning Tree. Edge Selection Greedy Strategies. Edge Selection Greedy Strategies

Example. Minimum-Cost Spanning Tree. Edge Selection Greedy Strategies. Edge Selection Greedy Strategies Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum cost Example 2 4 12 6 3 Network has 10 edges.

More information

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

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

More information

Graphs. The ultimate data structure. graphs 1

Graphs. The ultimate data structure. graphs 1 Graphs The ultimate data structure graphs 1 Definition of graph Non-linear data structure consisting of nodes & links between them (like trees in this sense) Unlike trees, graph nodes may be completely

More information

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

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

More information

Trees Algorhyme by Radia Perlman

Trees Algorhyme by Radia Perlman Algorhyme by Radia Perlman I think that I shall never see A graph more lovely than a tree. A tree whose crucial property Is loop-free connectivity. A tree which must be sure to span. So packets can reach

More information

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this Lecture Notes Array Review An array in C++ is a contiguous block of memory. Since a char is 1 byte, then an array of 5 chars is 5 bytes. For example, if you execute the following C++ code you will allocate

More information

Shortest path problems

Shortest path problems Next... Shortest path problems Single-source shortest paths in weighted graphs Shortest-Path Problems Properties of Shortest Paths, Relaxation Dijkstra s Algorithm Bellman-Ford Algorithm Shortest-Paths

More information

Info 2950, Lecture 16

Info 2950, Lecture 16 Info 2950, Lecture 16 28 Mar 2017 Prob Set 5: due Fri night 31 Mar Breadth first search (BFS) and Depth First Search (DFS) Must have an ordering on the vertices of the graph. In most examples here, the

More information

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

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

More information

CS6301 Programming and Data Structures II Unit -5 REPRESENTATION OF GRAPHS Graph and its representations Graph is a data structure that consists of following two components: 1. A finite set of vertices

More information

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

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

More information

CSE 100 Minimum Spanning Trees Prim s and Kruskal

CSE 100 Minimum Spanning Trees Prim s and Kruskal CSE 100 Minimum Spanning Trees Prim s and Kruskal Your Turn The array of vertices, which include dist, prev, and done fields (initialize dist to INFINITY and done to false ): V0: dist= prev= done= adj:

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305 Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n

More information

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee Algorithm Analysis Graph algorithm Chung-Ang University, Jaesung Lee Basic definitions Graph = (, ) where is a set of vertices and is a set of edges Directed graph = where consists of ordered pairs

More information

CS 310 Advanced Data Structures and Algorithms

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

More information

Directed Graphs. DSA - lecture 5 - T.U.Cluj-Napoca - M. Joldos 1

Directed Graphs. DSA - lecture 5 - T.U.Cluj-Napoca - M. Joldos 1 Directed Graphs Definitions. Representations. ADT s. Single Source Shortest Path Problem (Dijkstra, Bellman-Ford, Floyd-Warshall). Traversals for DGs. Parenthesis Lemma. DAGs. Strong Components. Topological

More information

Module 5 Graph Algorithms

Module 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 information

Representations of Graphs

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

More information

Outline. Graphs. Divide and Conquer.

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

More information

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD UNIT 3 Greedy Method GENERAL METHOD Greedy is the most straight forward design technique. Most of the problems have n inputs and require us to obtain a subset that satisfies some constraints. Any subset

More information

Lecture 9 Graph Traversal

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

More information

Graphs. Motivations: o Networks o Social networks o Program testing o Job Assignment Examples: o Code graph:

Graphs. Motivations: o Networks o Social networks o Program testing o Job Assignment Examples: o Code graph: Graphs Motivations: o Networks o Social networks o Program testing o Job Assignment Examples: o Code graph: S1: int x S2: If x > 0 then S3: X = x + 2; Else S4: X =x -1; End if S5: While x > 1 do S6: Print

More information

Elementary Graph Algorithms: Summary. Algorithms. CmSc250 Intro to Algorithms

Elementary Graph Algorithms: Summary. Algorithms. CmSc250 Intro to Algorithms Elementary Graph Algorithms: Summary CmSc250 Intro to Algorithms Definition: A graph is a collection (nonempty set) of vertices and edges A path from vertex x to vertex y : a list of vertices in which

More information

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

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

More information

Lecture 4: Graph Algorithms

Lecture 4: Graph Algorithms Lecture 4: Graph Algorithms Definitions Undirected graph: G =(V, E) V finite set of vertices, E finite set of edges any edge e = (u,v) is an unordered pair Directed graph: edges are ordered pairs If e

More information

CSC Intro to Intelligent Robotics, Spring Graphs

CSC 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 information

Algorithms Sequential and Parallel: A Unified Approach; R. Miller and L. Boxer 3rd Graph Algorithms

Algorithms Sequential and Parallel: A Unified Approach; R. Miller and L. Boxer 3rd Graph Algorithms Algorithms Sequential and Parallel: A Unified Approach; R. Miller and L. Boxer rd Edition @ 0 www.thestudycampus.com Graph Algorithms Terminology Representations Fundamental Algorithms Computing the Transitive

More information

Chapter 28 Graphs and Applications. Objectives

Chapter 28 Graphs and Applications. Objectives Chapter 28 Graphs and Applications CS2: Data Structures and Algorithms Colorado State University Original slides by Daniel Liang Modified slides by Chris Wilcox, Wim Bohm, and Russ Wakefield 1 Objectives

More information

Parallel Graph Algorithms

Parallel Graph Algorithms Parallel Graph Algorithms Design and Analysis of Parallel Algorithms 5DV050 Spring 202 Part I Introduction Overview Graphsdenitions, properties, representation Minimal spanning tree Prim's algorithm Shortest

More information

Homework Assignment #3 Graph

Homework Assignment #3 Graph CISC 4080 Computer Algorithms Spring, 2019 Homework Assignment #3 Graph Some of the problems are adapted from problems in the book Introduction to Algorithms by Cormen, Leiserson and Rivest, and some are

More information

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

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

More information

CSE 100: GRAPH ALGORITHMS

CSE 100: GRAPH ALGORITHMS CSE 100: GRAPH ALGORITHMS Dijkstra s Algorithm: Questions Initialize the graph: Give all vertices a dist of INFINITY, set all done flags to false Start at s; give s dist = 0 and set prev field to -1 Enqueue

More information

Homework 5: Graphs, Minimum Spanning Trees, and Dijkstra Shortest-Path

Homework 5: Graphs, Minimum Spanning Trees, and Dijkstra Shortest-Path Homework 5: Graphs, Minimum Spanning Trees, and Dijkstra Shortest-Path 1. (4 points) A graph is Hamiltonian if there is a cycle in the graph visiting each vertex exactly once. Give an example of an Eulerian

More information

Week 11: Minimum Spanning trees

Week 11: Minimum Spanning trees Week 11: Minimum Spanning trees Agenda: Minimum Spanning Trees Prim s Algorithm Reading: Textbook : 61-7 1 Week 11: Minimum Spanning trees Minimum spanning tree (MST) problem: Input: edge-weighted (simple,

More information

3.1 Basic Definitions and Applications

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

More information

CSI 604 Elementary Graph Algorithms

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

More information

Data Structure. IBPS SO (IT- Officer) Exam 2017

Data Structure. IBPS SO (IT- Officer) Exam 2017 Data Structure IBPS SO (IT- Officer) Exam 2017 Data Structure: In computer science, a data structure is a way of storing and organizing data in a computer s memory so that it can be used efficiently. Data

More information

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

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

More information

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

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

More information

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

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

More information

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

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

More information

Minimum Spanning Tree

Minimum Spanning Tree Minimum Spanning Tree 1 Minimum Spanning Tree G=(V,E) is an undirected graph, where V is a set of nodes and E is a set of possible interconnections between pairs of nodes. For each edge (u,v) in E, we

More information

CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs

CS/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 information

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

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

More information

CS420/520 Algorithm Analysis Spring 2009 Lecture 14

CS420/520 Algorithm Analysis Spring 2009 Lecture 14 CS420/520 Algorithm Analysis Spring 2009 Lecture 14 "A Computational Analysis of Alternative Algorithms for Labeling Techniques for Finding Shortest Path Trees", Dial, Glover, Karney, and Klingman, Networks

More information

CSE 100: GRAPH ALGORITHMS

CSE 100: GRAPH ALGORITHMS CSE 100: GRAPH ALGORITHMS 2 Graphs: Example A directed graph V5 V = { V = E = { E Path: 3 Graphs: Definitions A directed graph V5 V6 A graph G = (V,E) consists of a set of vertices V and a set of edges

More information

Unit #9: Graphs. CPSC 221: Algorithms and Data Structures. Will Evans 2012W1

Unit #9: Graphs. CPSC 221: Algorithms and Data Structures. Will Evans 2012W1 Unit #9: Graphs CPSC 1: Algorithms and Data Structures Will Evans 01W1 Unit Outline Topological Sort: Getting to Know Graphs with a Sort Graph ADT and Graph Representations Graph Terminology More Graph

More information

1 Digraphs. Definition 1

1 Digraphs. Definition 1 1 Digraphs Definition 1 Adigraphordirected graphgisatriplecomprisedofavertex set V(G), edge set E(G), and a function assigning each edge an ordered pair of vertices (tail, head); these vertices together

More information

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

End-Term Examination Second Semester [MCA] MAY-JUNE 2006 (Please write your Roll No. immediately) Roll No. Paper Code: MCA-102 End-Term Examination Second Semester [MCA] MAY-JUNE 2006 Subject: Data Structure Time: 3 Hours Maximum Marks: 60 Note: Question 1.

More information

Introductory Remarks

Introductory Remarks Chapter 8: Graphs Introductory Remarks Although trees are quite flexible, they have an inherent limitation in that they can only express hierarchical structures Fortunately, we can generalize a tree to

More information