Previous Up Previous Contents

6 Algorithms

Algorithms

GTL contains some basic algorithms like Depth-First-Search (DFS), Breadth-First-Search (BFS) or Biconnetivity-Test. All of them support the same (basic) interface described in their (abstract) base-class algorithm. The idea behind the decision to use a class representation for the algorithms (rather than to make them functions) was that all of them produce some data (e.g. DFS-numbers in DFS), which must be stored somewhere. If we used functions, the programer himself had to take care of these things. Furthermore funtions are useful if the algorithm only has one or two options, but if there are more options (and DFS can have quite a lot) one has to provide some way to tell the algorithm what to do and at this point classes are the better choice.

6.1 Common Interface

Common Interface

As already mentioned all algorithms inherit the basic interface from the class algorithm. Apart from constructor an destructor it defines three member functions:

6.2 Detailed Description

Detailed Description

The following algorithms are provided in GTL (Please refer to class-reference for details):

All these algorithms are customizable to some extent. This means that they support some options, such as the calculation of completion-numbers in DFS or the storing of non-tree edges both in DFS and BFS. But even the biggest set of options is not sufficient if one wants to add just a few lines of code to the DFS-algorithm in order to provide some new feature (e.g. the low-numbers in biconnectivity-testing). In that case the only possibility is to write the DFS-algorithm completely new and add the lines where necessary or to apply the given algorithm and then run through the nodes in DFS-order and add the new feature this way (which isn't even always possible).

So there should be some way to extend the given algorithm by a few new lines of code. In GTL this is achieved by calling virtual functions, so called handler, in all the (important) phases the algorithm runs through. Thus this algorithm can be used as base-class for an extended version of it, and the only thing to do is to write the new code in the appropriate handler. In GTL this is used to extend DFS by the code needed for the calculation of low-numbers and thus for testing biconnectivity. Please look at the corresponding files for details.


Previous Up Previous Contents