{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Graphs 1.8

# Graphs 1.8 - DFS Algorithm with Discovery and Finish Times...

This preview shows pages 1–5. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: DFS Algorithm with Discovery and Finish Times DFS-Visit (u) Precondition: vertex u is undiscovered Postcondition: all vertices reachable from u have been processed colour[u ] RED time time + 1 d[u] time for each v Adj[u ] //explore edge (u,v ) if color[v ] = BLACK DFS-Visit(v ) colour [u ] GRAY time time + 1 f [u ] time CSE 2011 Prof. J. Elder - 36 - Last Updated: 4/1/10 10:16 AM Other Variants of Depth-First Search The DFS Pattern can also be used to Compute a forest of spanning trees (one for each call to DFSvisit) encoded in a predecessor list [u] Label edges in the graph according to their role in the search (see textbook) Tree edges, traversed to an undiscovered vertex Forward edges, traversed to a descendent vertex on the current spanning tree Back edges, traversed to an ancestor vertex on the current spanning tree Cross edges, traversed to a vertex that has already been discovered, but is not an ancestor or a descendent CSE 2011 Prof. J. Elder - 37 - Last Updated: 4/1/10 10:16 AM Example DFS on Directed Graph CSE 2011 Prof. J. Elder - 38 - Last Updated: 4/1/10 10:16 AM DFS Note: Stack is Last-In First-Out (LIFO) s / b / a d / f / e / / g / c Found Not Handled Stack <node,# edges> f d / j / / i / h m / / k CSE 2011 Prof. J. Elder l - 39 - / Last Updated: 4/1/10 10:16 AM Found Not Handled Stack <node,# edges> DFS s 1/ b / a d / e / f / g / c / / j / / i / s,0 h m / / k CSE 2011 Prof. J. Elder l - 40 - / Last Updated: 4/1/10 10:16 AM ...
View Full Document

{[ snackBarMessage ]}

### Page1 / 5

Graphs 1.8 - DFS Algorithm with Discovery and Finish Times...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online