Tables 1.0 - a Linear Order Alg: DFS Found Not Handled...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a Linear Order Alg: DFS Found Not Handled Stack h i j k b c d e g f l Linear Order: CSE 2011 Prof. J. Elder a,h,b,c,i,j,k,d,e,g,l,f Done! - 116 - Last Updated: 4/1/10 10:16 AM DFS Application 3. Topological Sort Topological-Sort(G) Precondition: G is a graph Postcondition: all vertices in G have been pushed onto stack in reverse linear order for each vertex u V [G] color[u] = BLACK //initialize vertex for each vertex u V [G] if color[u] = BLACK //as yet unexplored Topological-Sort-Visit(u) CSE 2011 Prof. J. Elder - 117 - Last Updated: 4/1/10 10:16 AM DFS Application 3. Topological Sort Topological-Sort-Visit (u) Precondition: vertex u is undiscovered Postcondition: u and all vertices reachable from u have been pushed onto stack in reverse linear order colour[u ] RED for each v Adj[u ] //explore edge (u,v ) if color[v ] = BLACK Topological-Sort-Visit(v ) push u onto stack colour [u ] GRAY CSE 2011 Prof. J. Elder - 118 - Last Updated: 4/1/10 10:16 AM Breadth-First Search CSE 2011 Prof. J. Elder - 119 - Last Updated: 4/1/10 10:16 AM Breadth-First Search Breadth-first search (BFS) is a general technique for traversing a graph A BFS traversal of a graph G Visits all the vertices and edges of G Determines whether G is connected Computes the connected components of G Computes a spanning forest of G BFS on a graph with |V| vertices and |E| edges takes O(|V|+|E|) time BFS can be further extended to solve other graph problems Find and report a path with the minimum number of edges between two given vertices Find a simple cycle, if there is one CSE 2011 Prof. J. Elder - 120 - Last Updated: 4/1/10 10:16 AM ...
View Full Document

Ask a homework question - tutors are online