12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sec. 11.3 Graph Traversals 405ABABCCDDFFEE(a)(b)Figure 11.11 (a) A graph. (b) The breadth-first search tree for the graph whenstarting at Vertex A.A <strong>to</strong>pological sort may be found by performing a DFS on the graph. When avertex is visited, no action is taken (i.e., function PreVisit does nothing). Whenthe recursion pops back <strong>to</strong> that vertex, function PostVisit prints the vertex. Thisyields a <strong>to</strong>pological sort in reverse order. It does not matter where the sort starts,as long as all vertices are visited in the end. Here is an implementation for theDFS-based algorithm.static void <strong>to</strong>psort(Graph G) { // Recursive <strong>to</strong>pological sortfor (int i=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!