Graphs 2015, Fall Pusan National University Ki-Joune Li.

Slides:



Advertisements
Similar presentations
Graph Algorithms Algorithm Design and Analysis Victor AdamchikCS Spring 2014 Lecture 11Feb 07, 2014Carnegie Mellon University.
Advertisements

What is a graph ? G=(V,E) V = a set of vertices E = a set of edges edge = unordered pair of vertices
Lecture 15. Graph Algorithms
Graphs - II Algorithms G. Miller V. Adamchik CS Spring 2014 Carnegie Mellon University.
CHAPTER 6 GRAPHS All the programs in this file are selected from
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Chapter 6. Konigsberg Bridge Problem A river Pregel flows around the island Keniphof and then divides into two. Four land areas A, B, C, D have this river.
Minimum cost spanning tree and activity networks Data structure 2002/12/2.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Chapter 8, Part I Graph Algorithms.
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
Graph & BFS.
Chapter 6 張啟中. Kongsberg Bridge Problem (1736) A Kneiphof a b c d g C D B f e a b c d g e f A B C D Euler’s graph.
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
Chapter 9: Graphs Summary Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
CS Data Structures Chapter 6 Graphs.
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.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Tirgul 7 Review of graphs Graph algorithms: – BFS (next tirgul) – DFS – Properties of DFS – Topological sort.
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
GRAPHS Education is what remains after one has forgotten what one has learned in school. Albert Einstein Albert Einstein Smitha N Pai.
Graph. Data Structures Linear data structures: –Array, linked list, stack, queue Non linear data structures: –Tree, binary tree, graph and digraph.
IS 2610: Data Structures Graph April 5, 2004.
Course notes CS2606: Data Structures and Object-Oriented Development Graphs Department of Computer Science Virginia Tech Spring 2008 (The following notes.
The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each decision is locally optimal. These.
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
Copyright Networking Laboratory Chapter 6. GRAPHS Horowitz, Sahni, and Anderson-Freed Fundamentals of Data Structures in C, 2nd Edition Computer.
Been-Chian Chien, Wei-Pang Yang, and Wen-Yang Lin 6-1 Chapter 6 Graphs Introduction to Data Structure CHAPTER 6 GRAPHS 6.1 The Graph Abstract Data Type.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Spring 2015 Lecture 10: Elementary Graph Algorithms
Chapter 2 Graph Algorithms.
CS200 Algorithms and Data StructuresColorado State University Part 10. Graphs CS 200 Algorithms and Data Structures 1.
1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Lecture 11 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 20.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Graphs 황승원 Fall 2010 CSE, POSTECH. 2 2 Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects.
Chapter 6 Graphs. 2 Outline Definitions, Terminologies and Applications Graph Representation Elementary graph operations Famous Graph Problems.
Shahed University Dr. Shahriar Bijani May  A path is a sequence of vertices P = (v 0, v 1, …, v k ) such that, for 1 ≤ i ≤ k, edge (v i – 1, v.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
Lecture #13. Topics 1.The Graph Abstract Data Type. 2.Graph Representations. 3.Elementary Graph Operations.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Graphs. What is a graph? In simple words, A graph is a set of vertices and edges which connect them. A node (or vertex) is a discrete position in the.
1 Data Structures and Algorithms Graphs. 2 Graphs Basic Definitions Paths and Cycles Connectivity Other Properties Representation Examples of Graph Algorithms:
Chapter 5 : Trees.
C.Eng 213 Data Structures Graphs Fall Section 3.
Unit 3 Graphs.
CS120 Graphs.
Graph Algorithms Using Depth First Search
Autumn 2016 Lecture 11 Minimum Spanning Trees (Part II)
Graph Algorithm.
Elementary graph algorithms Chapter 22
2018, Fall Pusan National University Ki-Joune Li
Chapter 11 Graphs.
2017, Fall Pusan National University Ki-Joune Li
Text Book: Introduction to algorithms By C L R S
Elementary graph algorithms Chapter 22
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
GRAPH TRAVERSAL.
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Graphs 2015, Fall Pusan National University Ki-Joune Li

STEMPNU 2 Graph Definition  G = (V,E ) where V : a set of vertices and E = { | u,v  V } : a set of edges Some Properties  Equivalence of Graphs  Tree a Graph Minimal Graph a b c d e a c b d e

STEMPNU 3 Some Terms Directed Graph  G is a directed graph iff  for u  v  V  Otherwise G is an undirected graph Complete Graph  Suppose n v = number(V )  Undirected graph G is a complete graph if n e = n v (n v - 1) / 2, where n e is the number of edges Adjacency  For a graph G=(V,E ) u is adjacent to v iff  e =  E, where u,v  V  If G is undirected, v is adjacent to u otherwise v is adjacent from u

STEMPNU 4 Some Terms Subgraph  G’ is a subgraph of a graph G iff V (G’ )  V (G ) and E (G’ )  E (G ) Path from u to v  A sequence of vertices u=v 0, v 1, v 2, … v n =v  V, such that  E for every v i  Cycle iff u = v Connected  Two vertices u and v are connected iff  a path from u to v  Graph G is connected iff for every pair u and v there is a path from u to v  Connected Components A connected subgraph of G

STEMPNU 5 Some Terms Strongly Connected  An directed graph G is strongly connected iff iff for every pair u and v there is a path from u to v and path from v to u  DAG: directed acyclic graph (DAG) In-degree and Out-Degree  In-degree of v : number of edges coming to v  Out-degree of v : number of edges going from v

STEMPNU 6 Representation of Graphs: Matrix Adjacency Matrix  A[i, j ] = 1, if there is an edge A[i, j ] = 0, otherwise  Example  Undirected Graph: Symmetric Matrix  Space complexity: O (n v 2 ) bits  In-degree (out-degree) of a node

STEMPNU 7 Representation of Graphs: List Adjacency List  Each node has a list of adjacent nodes  Space Complexity: O (n v + n e )  Inverse Adjacent List

STEMPNU 8 Weighted Graph: Network For each edge, a weight is given  Example: Road Network  Adjacency Matrix A[i, j ] = w ij, if there is an edge and w ij is the weight A[i, j ] = , otherwise  Adjacency List   1.0   1.9 

STEMPNU 9 Graph: Basic Operations Traversal  Depth First Search (DFS)  Breadth First Search (BFS)  Used for search  Example Find Yellow Node from

STEMPNU 10 DFS: Depth First Search void Graph::DFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; DFS(0); delete[] visited; } void Graph::DFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; DFS(0); delete[] visited; } void Graph::DFS(int v) { visited[v]=TRUE; for each u adjacent to v { if(visited[u]==FALSE) DFS(u); } void Graph::DFS(int v) { visited[v]=TRUE; for each u adjacent to v { if(visited[u]==FALSE) DFS(u); } Adjacency List: Time Complexity: O(e) Adjacency Matrix: Time Complexity: O(n 2 )

STEMPNU DFS: Depth First Search DFS(0) void Graph::DFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; DFS(0); delete[] visited; } void Graph::DFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; DFS(0); delete[] visited; } void Graph::DFS(int v) { visited[v]=TRUE; for each u adjacent to v { if(visited[u]==FALSE) DFS(u); } void Graph::DFS(int v) { visited[v]=TRUE; for each u adjacent to v { if(visited[u]==FALSE) DFS(u); }

STEMPNU DFS: Depth First Search DFS(1) void Graph::DFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; DFS(0); delete[] visited; } void Graph::DFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; DFS(0); delete[] visited; } void Graph::DFS(int v) { visited[v]=TRUE; for each u adjacent to v { if(visited[u]==FALSE) DFS(u); } void Graph::DFS(int v) { visited[v]=TRUE; for each u adjacent to v { if(visited[u]==FALSE) DFS(u); }

STEMPNU DFS: Depth First Search DFS(4) void Graph::DFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; DFS(0); delete[] visited; } void Graph::DFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; DFS(0); delete[] visited; } void Graph::DFS(int v) { visited[v]=TRUE; for each u adjacent to v { if(visited[u]==FALSE) DFS(u); } void Graph::DFS(int v) { visited[v]=TRUE; for each u adjacent to v { if(visited[u]==FALSE) DFS(u); }

STEMPNU DFS: Depth First Search DFS(5) void Graph::DFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; DFS(0); delete[] visited; } void Graph::DFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; DFS(0); delete[] visited; } void Graph::DFS(int v) { visited[v]=TRUE; for each u adjacent to v { if(visited[u]==FALSE) DFS(u); } void Graph::DFS(int v) { visited[v]=TRUE; for each u adjacent to v { if(visited[u]==FALSE) DFS(u); }

STEMPNU DFS: Depth First Search DFS(7) void Graph::DFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; DFS(0); delete[] visited; } void Graph::DFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; DFS(0); delete[] visited; } void Graph::DFS(int v) { visited[v]=TRUE; for each u adjacent to v { if(visited[u]==FALSE) DFS(u); } void Graph::DFS(int v) { visited[v]=TRUE; for each u adjacent to v { if(visited[u]==FALSE) DFS(u); }

STEMPNU 16 BFS: Breadth First Search void Graph::BFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; Queue *queue=new Queue; queue.insert(v); while(queue.empty()!=TRUE) { v=queue.delete() for every w adjacent to v) { if(visited[w]==FALSE) { queue.insert(w); visited[w]=TRUE; } delete[] visited; } void Graph::BFS() { visited=new Boolean[n]; for(i=0;i<n;i++)visited[i]=FALSE; Queue *queue=new Queue; queue.insert(v); while(queue.empty()!=TRUE) { v=queue.delete() for every w adjacent to v) { if(visited[w]==FALSE) { queue.insert(w); visited[w]=TRUE; } delete[] visited; } Adjacency List: Time Complexity: O(e) Adjacency Matrix: Time Complexity: O(n 2 )

STEMPNU 17 Spanning Tree A subgraph T of G = (V,E ) is a spanning tree of G  iff T is tree and V (T )=V (G ) Finding Spanning Tree: Traversal  DFS Spanning Tree  BFS Spanning Tree

STEMPNU 18 Articulation Point  A vertex v of a graph G is an articulation point iff the deletion of v makes G two connected components Biconnected Graph  Connected Graph without articulation point Biconnected Components of a graph Articulation Point and Biconnected Components

STEMPNU 19 Finding Articulation Point: DFS Tree Back Edge and Cross Edge of DFS Spanning Tree  Tree edge: edge of tree  Back edge: edge to an ancestor  Cross edge: neither tree edge nor back edge No cross edge for DFS spanning tree a b h d e fc g a b h d e f c g Back edge

STEMPNU 20 Finding Articulation Point Articulation point  Root is an articulation point if it has at least two children.  u is an articulation point if  child of u without back edge to an ancestor of u a b h d e f c g Back edge

STEMPNU 21 Finding Articulation Point by DFS Number DFS number of a vertex: dfn (v )  The visit number by DFS Low number: low (v )  low (v )= min{ dfn (v ), min{dfn (x )| (v, x ): back edge }, min{low (x )| x : child of v } } v is an articulation Point  If v is the root node with at least two children or  If v has a child u such that low (u )  dfn (v ) v is the boss of subtree: if v dies, the subtree looses the line

STEMPNU Finding Articulation Point by DFS Number 22 node e has two paths; one along dfs path, and another via back edge.  not articulation point a b h d e f c g

STEMPNU Finding Articulation Point by DFS Number 23 node c has two paths; one along dfs path, and another via a descendant node  not articulation point a b h d e f c g

STEMPNU Finding Articulation Point by DFS Number 24 node a has only one path; along dfs path  its parent node is an articulation point since it will be disconnected if its parent is deleted. (node a relies only on its parent.) a b h d e f c g

STEMPNU 25 Computation of dfs (v ) and low (v ) void Graph::DfnLow(x) { num=1; // num: class variable for(i=0;i<n;i++) dfn[i]=low[i]=0; DfnLow(x,-1);//x is the root node } void Graph::DfnLow(x) { num=1; // num: class variable for(i=0;i<n;i++) dfn[i]=low[i]=0; DfnLow(x,-1);//x is the root node } void Graph::DfnLow(int u,v) { dfn[u]=low[u]=num++; for(each vertex w adjacent from u){ if(dfn[w]==0) // unvisited w DfnLow(w,u); low[w]=min(low[u],low[w]); else if(w!=v) low[u]=min(low[u],dfn[w]); //back edge } void Graph::DfnLow(int u,v) { dfn[u]=low[u]=num++; for(each vertex w adjacent from u){ if(dfn[w]==0) // unvisited w DfnLow(w,u); low[w]=min(low[u],low[w]); else if(w!=v) low[u]=min(low[u],dfn[w]); //back edge } Adjacency List: Time Complexity: O(e) Adjacency Matrix: Time Complexity: O(n 2 )

STEMPNU 26 Minimum Spanning Tree G is a weighted graph  T is the MST of G iff T is a spanning tree of G and for any other spanning tree of G, C (T ) < C (T’ )

STEMPNU 27 Finding MST Greedy Algorithm  Choosing a next branch which looks like better than others.  Not always the optimal solution Kruskal’s Algorithm and Prim’s Algorithm  Two greedy algorithms to find MST Current state Solution by greedy algorithm, only locally optimal Globally optimal solution

STEMPNU 28 Kruskal’s Algorithm Algorithm KruskalMST Input: Graph G Output: MST T Begin T  {}; while( n(T)<n-1 and G.E is not empty) { (v,w)  smallest edge of G.E; G.E  G.E-{(v,w)}; if no cycle in {(v,w)}  T, T  {(v,w)}  T } if(n(T)<n-1) cout<<“No MST”; End Algorithm Algorithm KruskalMST Input: Graph G Output: MST T Begin T  {}; while( n(T)<n-1 and G.E is not empty) { (v,w)  smallest edge of G.E; G.E  G.E-{(v,w)}; if no cycle in {(v,w)}  T, T  {(v,w)}  T } if(n(T)<n-1) cout<<“No MST”; End Algorithm X X T is MST Time Complexity: O(e loge)

STEMPNU 29 Checking Cycles for Kruskal’s Algorithm v 1 2 V V1V1 V2V2 If v  V and w  V, then  cycle, otherwise no cycle w log n

STEMPNU 30 Prim’s Algorithm Algorithm PrimMST Input: Graph G Output: MST T Begin V new  {v 0 }; E new  {}; while( n(E new )<n-1) { select v such that (u,v) is the smallest edge where u  V new, v  V new ; if no such v, break; G.E  G.E-{(u,v)}; E new  {(u,v)}  E new ; V new  {v}  V new ; } if(n(T)<n-1) cout<<“No MST”; End Algorithm Algorithm PrimMST Input: Graph G Output: MST T Begin V new  {v 0 }; E new  {}; while( n(E new )<n-1) { select v such that (u,v) is the smallest edge where u  V new, v  V new ; if no such v, break; G.E  G.E-{(u,v)}; E new  {(u,v)}  E new ; V new  {v}  V new ; } if(n(T)<n-1) cout<<“No MST”; End Algorithm T is the MST Time Complexity: O( n 2 )

STEMPNU 31 Finding the Edge with Min-Cost Step 1 n n - 1 Step 2 n + (n-1) +… 1 = O( n 2 ) TV V T

STEMPNU 32 Shortest Path Problem Shortest Path  From 0 to all other vertices vertexcost

STEMPNU 33 Shortest Path Problem Shortest Path  Step 1 vertexcost ? 5? 6? 7? TV V-TV

STEMPNU 34 Shortest Path Problem Shortest Path  Step 1 vertexcost ? 5? 6? 7? TV V-TV

STEMPNU 35 Shortest Path Problem Shortest Path  Step 2 vertexcost 15 2868 ?8?8 5?7?7 6? 7? ? ? ∞ TV V-TV ? ∞

STEMPNU 36 Shortest Path Problem Shortest Path  Step 2 vertexcost 15 2868 ?8?8 5?7?7 6? 7? ? ? ∞ TV V-TV ? ∞

STEMPNU 37 Shortest Path Problem Shortest Path  Step 2 vertexcost 15 2868 ?8?8 5?7?7 6? 7? ? ∞ TV V-TV ? ∞

STEMPNU 38 Finding Shortest Path from Single Source (Nonnegative Weight) Algorithm DijkstraShortestPath(G) /* G=(V,E) */ output: Shortest Path Length Array D[n] Begin S  {v 0 }; D[v 0 ]  0; for each v in V-{v 0 }, do D[v]  c(v 0,v); while S  V do begin choose a vertex w in V-S such that D[w] is minimum; add w to S; for each v in V-S do D[v]  min(D[v],D[w]+c(w,v)); end End Algorithm Algorithm DijkstraShortestPath(G) /* G=(V,E) */ output: Shortest Path Length Array D[n] Begin S  {v 0 }; D[v 0 ]  0; for each v in V-{v 0 }, do D[v]  c(v 0,v); while S  V do begin choose a vertex w in V-S such that D[w] is minimum; add w to S; for each v in V-S do D[v]  min(D[v],D[w]+c(w,v)); end End Algorithm w uv S O( n 2 )

STEMPNU 39 Finding Shortest Path from Single Source (Nonnegative Weight) ∞ ∞ 1: {v 0 } ∞ 2: {v 0, v 1 } : {v 0, v 1, v 2 } : {v 0, v 1, v 2, v 4 } : {v 0, v 1, v 2, v 3, v 4 }

STEMPNU 40 Transitive Closure A A+A+ A*A*  Set of reachable nodes

STEMPNU 41 Transitive Closure Void Graph::TransitiveClosure { for(int i=0;i<n;i++) for (int j=0;i<n;j++) a[i][j]=c[i][j]; for(int k=0;k<n;k++) for(int i=0;i<n;i++) for (int j=0;i<n;j++) a[i][j]= a[i][j]||(a[i][k] && a[k][j]); } Void Graph::TransitiveClosure { for(int i=0;i<n;i++) for (int j=0;i<n;j++) a[i][j]=c[i][j]; for(int k=0;k<n;k++) for(int i=0;i<n;i++) for (int j=0;i<n;j++) a[i][j]= a[i][j]||(a[i][k] && a[k][j]); } O ( n 3 ) Void Graph::AllPairsShortestPath { for(int i=0;i<n;i++) for (int j=0;i<n;j++) a[i][j]=c[i][j]; for(int k=0;k<n;k++) for(int i=0;i<n;i++) for (int j=0;i<n;j++) a[i][j]= min(a[i][j],(a[i][k]+a[k][j])); } Void Graph::AllPairsShortestPath { for(int i=0;i<n;i++) for (int j=0;i<n;j++) a[i][j]=c[i][j]; for(int k=0;k<n;k++) for(int i=0;i<n;i++) for (int j=0;i<n;j++) a[i][j]= min(a[i][j],(a[i][k]+a[k][j])); } O ( n 3 )

STEMPNU Activity Networks 42

STEMPNU AOV – Activity-on-vertex Node 1 is a immediate successor of Node 0 Node 5 is a immediate successor of Node 1 Node 5 is a successor of Node 0 Node 0 is a predecessor of Node 5 Partial order: for some pairs (v, w) (v, w  V ), v  w (but not for all pairs) (cf. Total Order: for every pair (v, w) (v, w  V ), v  w or w  v ) Node 0  Node 1 Node 1  Node 5 Node 0  Node 5 No Cycle Transitive and Irreflexive

STEMPNU Topological Order Ordering: (0, 1, 2, 3, 4, 5, 7, 6) Ordering: (0, 1, 4, 2, 3, 5, 7, 6) Ordering: (0, 1, 2, 3, 4, 5, 7, 6) Ordering: (0, 1, 4, 2, 3, 5, 7, 6) Both orderings satisfy the partial order Topological order: Ordering by partial order Ordering: (0, 1, 2, 5, 4, 3, 7, 6): Not a topological order

STEMPNU Topological Ordering , , 1, , 1, 4, 2

STEMPNU Topological Ordering 46 Void Topological_Ordering_AOV(Digraph G) for each node v in G.V { if v has no predecessor { cout << v; delete v from G.V; deleve (v,w) from G.E; } if G.V is not empty, cout <<“Cycle found\n”; } Void Topological_Ordering_AOV(Digraph G) for each node v in G.V { if v has no predecessor { cout << v; delete v from G.V; deleve (v,w) from G.E; } if G.V is not empty, cout <<“Cycle found\n”; } O ( n + e )

STEMPNU AOE – Activity-on-edge PERT (Project Evaluation and Review Technique Node 2 is completed only if every predecessor is completed Required Time: the LONGEST PATH from node 0  Required time of node 1: 5  Required time of node 2: 8  Required time of node 4: 8  Required time of node 5: max(8+11, 5+2, 8+6)=19  Required time of node 7: max(8+9, 19+4)=23  Required time of node 6: max(23+12, 19+6)=35 Node 2 is completed only if every predecessor is completed Required Time: the LONGEST PATH from node 0  Required time of node 1: 5  Required time of node 2: 8  Required time of node 4: 8  Required time of node 5: max(8+11, 5+2, 8+6)=19  Required time of node 7: max(8+9, 19+4)=23  Required time of node 6: max(23+12, 19+6)=35 (0, 1, 4, 5, 7, 6) : Critical Path By reducing the length on the critical path, we can reduce the length of total path. (0, 1, 4, 5, 7, 6) : Critical Path By reducing the length on the critical path, we can reduce the length of total path