Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
Directed graphs and undirected graphs have many common characteristics. In addition, we can view a directed graph as an undirected graph with arrowheads added. As shown in Figure , we have chosen to define the Graph interface to represent undirected graphs and to derive Digraph interface from it. We have chosen this approach because many algorithms for undirected graphs can also be used with directed graphs. On the other hand, it is often the case that algorithms for directed graphs cannot be used with undirected graphs.
Program defines the Graph interface. The Graph interface extends the Container interface defined in Program .
There are essentially three groups of methods declared in Program : accessors and mutators, enumerators, and traversals. The operations performed by the methods are explained in the following sections.