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.

arithmetic demand for each function below. If the arithmetic incurs rounding error, the<br />

computation may fail in two ways: give a wrong answer or run forever.<br />

12.1 Basic Graph Algorithms ( basic graph alg )<br />

bool<br />

TOPSORT(const graph& G, node array& ord)<br />

TOPSORT takes as argument a directed graph G(V, E). It sorts G topologically<br />

(if G is acyclic) by computing for every node v ∈ V an integer<br />

ord[v] such that 1 ≤ ord[v] ≤ |V | and ord[v] < ord[w] for all edges<br />

(v, w) ∈ E. TOPSORT returns true if G is acyclic and false otherwise.<br />

<strong>The</strong> algorithm ([50]) has running time O(|V | + |E|).<br />

bool TOPSORT(const graph& G, list& L)<br />

a variant of TOPSORT that computes a list L of nodes in topological<br />

order (if G is acyclic). It returns true if G is acyclic and false otherwise.<br />

list DFS(const graph& G, node s, node array& reached)<br />

DFS takes as argument a directed graph G(V, E), a node s of G and a<br />

node array reached of boolean values. It performs a depth first search<br />

starting at s visiting all reachable nodes v with reached[v] = false. For<br />

every visited node v reached[v] is changed to true. DFS returns the list<br />

of all reached nodes. <strong>The</strong> algorithm ([85]) has running time O(|V | + |E|).<br />

list DFS NUM(const graph& G, node array& dfsnum,<br />

node array& compnum)<br />

DFS NUM takes as argument a directed graph G(V, E). It performs a<br />

depth first search of G numbering the nodes of G in two different ways.<br />

dfsnum is a numbering with respect to the calling time and compnum<br />

a numbering with respect to the completion time of the recursive calls.<br />

DFS NUM returns a depth first search forest of G (list of tree edges).<br />

<strong>The</strong> algorithm ([85]) has running time O(|V | + |E|).<br />

list BFS(const graph& G, node s, node array& dist)<br />

BFS takes as argument a directed graph G(V, E),a node s of G and a<br />

node array dist of integers. It performs a breadth first search starting at<br />

s visiting all nodes v with dist[v] = −1 reachable from s. <strong>The</strong> dist value<br />

of every visited node is replaced by its distance to s. BFS returns the list<br />

of all visited nodes. <strong>The</strong> algorithm ([58]) has running time O(|V | + |E|).

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

Saved successfully!

Ooh no, something went wrong!