Graphs 1.6 - Depth-First Search Explore every edge,...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Depth-First Search Explore every edge, starting from different vertices if necessary. As soon as vertex discovered, explore from it. Keep track of progress by colouring vertices: Black: undiscovered vertices Red: discovered, but not finished (still exploring from it) Gray: finished (found everything reachable from it). CSE 2011 Prof. J. Elder - 26 - Last Updated: 4/1/10 10:16 AM DFS Example on Undirected Graph A unexplored A being explored A finished A B unexplored edge discovery edge D E D E C back edge A B A D E B C CSE 2011 Prof. J. Elder C - 27 - Last Updated: 4/1/10 10:16 AM Example (cont.) A B A D E B D D C E C A E A B D E B C CSE 2011 Prof. J. Elder C - 28 - Last Updated: 4/1/10 10:16 AM DFS Algorithm Pattern DFS(G) Precondition: G is a graph Postcondition: all vertices in G have been visited for each vertex u V [G] color[u] = BLACK //initialize vertex for each vertex u V [G] if color[u] = BLACK //as yet unexplored DFS-Visit(u) CSE 2011 Prof. J. Elder - 29 - Last Updated: 4/1/10 10:16 AM DFS Algorithm Pattern DFS-Visit (u) Precondition: vertex u is undiscovered Postcondition: all vertices reachable from u have been processed colour[u ] RED for each v Adj[u ] //explore edge (u,v ) if color[v ] = BLACK colour [u ] CSE 2011 Prof. J. Elder DFS-Visit(v ) GRAY - 30 - 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.

Page1 / 5

Graphs 1.6 - Depth-First Search Explore every edge,...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online