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
TopologicalSort(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
TopologicalSortVisit(u) CSE 2011
Prof. J. Elder  117  Last Updated: 4/1/10 10:16 AM DFS Application 3. Topological Sort
TopologicalSortVisit (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
TopologicalSortVisit(v )
push u onto stack
colour [u ] GRAY
CSE 2011
Prof. J. Elder  118  Last Updated: 4/1/10 10:16 AM BreadthFirst Search CSE 2011
Prof. J. Elder  119  Last Updated: 4/1/10 10:16 AM BreadthFirst Search
Breadthfirst 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
This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.
 Fall '11
 Elder
 Data Structures, Sort

Click to edit the document details