31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

With this iterator you can easily iterate through a graph in breadth first fashion :<br />

graph G;<br />

BFS_It it(G);<br />

while (it.valid()) {<br />

// do something reasonable with ’it.get_node()’<br />

++it;<br />

}<br />

5. Implementation<br />

Each operation requires constant time. <strong>The</strong>refore, a normal breadth-first search needs<br />

O(m + n) time.<br />

13.18 Depth First Search (flexible) ( GIT DFS )<br />

1. Definition<br />

An instance algorithm of class GIT DFS< OutAdjIt, Stacktype, Mark > is an implementation<br />

of an algorithm that traverses a graph in a depth first order. <strong>The</strong> stack used for<br />

the search must be provided by the caller and contains the source(s) of the search.<br />

• If the stack is only modified by pushing the iterator representing the source node<br />

onto the stack, a normal depth first search beginning at the node of the graph is<br />

performed.<br />

• It is possible to initialize the stack with several iterators that represent different<br />

roots of depth first trees.<br />

• By modifying the stack while running the algorithm the behaviour of the algorithm<br />

can be changed.<br />

• After the algorithm performed a depth first search, one may push another iterator<br />

onto the stack to restart the algorithm.<br />

A next step may return a state which describes the last action. <strong>The</strong>re are the following<br />

three possibilities:<br />

1. dfs shrink: an adjacency iterator was popped from the stack, i.e. the treewalk<br />

returns in root-direction<br />

2. dfs leaf: same as dfs shrink, but a leaf occured

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

Saved successfully!

Ooh no, something went wrong!