18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

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.

Breadth-First Search<br />

``discovered''<br />

for each do<br />

process edge (u,v) as desired<br />

if state[v] = ``undiscovered'' then<br />

state[u] = ``completely-explored''<br />

state[v] =<br />

p[v] = u<br />

enqueue[Q,v]<br />

<strong>The</strong> graph edges that do not appear in the breadth-first search tree also have special properties. For undirected graphs, nontree<br />

edges can point only to vertices on the same level as the parent vertex or to vertices on the level directly below the<br />

parent. <strong>The</strong>se properties follow easily from the fact that each path in the tree must be the shortest path in the graph. For a<br />

directed graph, a back-pointing edge can exist whenever v lies closer to the root than u does.<br />

<strong>The</strong> breadth-first search algorithm above includes places to optionally process each vertex and edge, say to copy them, print<br />

them, or count them. Each vertex and directed edge is encountered exactly once, and each undirected edge is encountered<br />

exactly twice.<br />

Next: Depth-First Search Up: Traversing a Graph Previous: Traversing a Graph<br />

<strong>Algorithm</strong>s<br />

Mon Jun 2 23:33:50 EDT 1997<br />

file:///E|/BOOK/BOOK2/NODE64.HTM (2 of 2) [19/1/2003 1:29:06]

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

Saved successfully!

Ooh no, something went wrong!