Exercise Set 6: Graph Algorithms

Exercise 6.1 The goal of this exercise is to learn to represent a graph as a data structure.
The graph structure is defined as follows.

  1. Draw the UML diagram of the graph data structure.

  2. Implement the method getNodes for the class Graph, which creates the hashtable of Nodes using a given IRange iterator. Make sure the hashtable does not have duplicate entries.

  3. Implement the method addEdge, which adds an edge to the graph, given the start and end Object and the distance.

  4. Implement the method addEdges, which adds edges to the graph, using the given IRange iterator.

  5. Implement the iterator() method for the class Graph, which returns an iterator for traversing over the graph nodes.

  6. Implement the iterator() method for the class Node, which returns an iterator for traversing over the edges adjacent to this node.

  7. Verify your work by displaying a graph of cities using the GraphDisplay class.

Exercise 6.2 The goal of this exercise is to implement some basic graph algorithms.
The GraphAlgorithms class contains the following member data:

  1. Define the GraphAlgorithms class and implement the constructor which takes the graph, the start and target Node, and the fringeQueue as arguments.

  2. Define the method initialize, which inserts the start Node into the fringeHash, and also into the fringeQueue with distance 0 and the finish Node being the same as start Node.

  3. Define the method processNode, as follows:

  4. Define the method processEdge, as follows:

  5. Define the perform method as follows:

  6. Define the getPath method, which for a given start and finish Nodes returns a list of edges leading from start to finish in the result Graph.