23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

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

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

came from to get to v, <strong>and</strong> repeat the procedure at that vertex. Thus, we cont<strong>in</strong>ue to<br />

backtrack along the path that we have traced so far until we f<strong>in</strong>d a vertex that has<br />

yet unexplored edges, take one such edge, <strong>and</strong> cont<strong>in</strong>ue the traversal. The process<br />

term<strong>in</strong>ates when our backtrack<strong>in</strong>g leads us back to the start vertex s, <strong>and</strong> there are<br />

no more unexplored edges <strong>in</strong>cident on s.<br />

This simple process traverses all the edges of G. (See Figure 13.6.)<br />

Figure 13.6: Example of depth-first search traversal<br />

on a graph start<strong>in</strong>g at vertex A. Discovery edges are<br />

shown with solid l<strong>in</strong>es <strong>and</strong> back edges are shown with<br />

dashed l<strong>in</strong>es: (a) <strong>in</strong>put graph; (b) path of discovery<br />

edges traced from A until back edge (B,A) is hit; (c)<br />

reach<strong>in</strong>g F, which is a dead end; (d) after backtrack<strong>in</strong>g<br />

to C, resum<strong>in</strong>g with edge (C,G), <strong>and</strong> hitt<strong>in</strong>g another<br />

dead end, J; (e) after backtrack<strong>in</strong>g to G; (f) after<br />

backtrack<strong>in</strong>g to N.<br />

809

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

Saved successfully!

Ooh no, something went wrong!