CSci2110 - Assignment 5
Due:
Tuesday April 3rd before 11:55 pm
Revisions History:
- Created Feb. 27th, 2007
This is an exercise in creating
your own reusable implementation of the UndirectedGraph
ADT. Please read the chapter of your textbook covering
graphs very carefully. In completing this assignment you may use
code you have developed previously in this class, or
code in the Java util package. You may also you the
code fragments given in the text.
In order to help test your class I have created an application that creates
files containing random graphs. By looking at the main in this class you can see
how to read these files.
You may be interested in the graph drawing program Graphviz (available from
http://www.graphviz.org/) with minimal
work you can use it to visualize the graphs you create. This can be very handy
for debugging purposes.
|
Question 0: Implementing the UndirectedGraph ADT | |
Construct your own reusable
implementation of the UndirectedGraph
ADT based on an adjacency list representation.
You are to also create a class, TestGraphClass, with a main() method that
performs the following actions:
-
Create the UndirectedGraph G illustrated below (can be hard-coded into the
main() method):

-
Call TestGraphClass.printAdjacencies(G) on this graph.
-
Design a sequence of tests on this graph the exercises all of the methods in
your undirected graph class
-
Perform the following actions:
-
Using the graph generator provides, create the following files
- n=300, m=500, seed 349
- n=100, m=300, seed 12554
- n=1000, m=1200, seed 369
- n=100, m=4800, seed 9873
-
For each file print the following statistics
- Node with greatest degree (e.g. Max degree: Node 5 with degree 8)
- Node with smallest degree (e.g. Min degree: Node 301 with degree 0)
- Perform a sequence of experiments to determine for a randomly created
undirected graph with n vertices and m Î {n...((n2-n)/2)}edges
what the expected max and min degree is. Draw some conclusions.
Summary
- Create class MyUndirectedGraph that implements the UndirectedGraph
interface
- Create class TestGraphClass that contains testing methods for class
MyUndirectedGraph
- Do testing and experiments and write up the results
|
Question 1: Implementing Depth First Search
& Breadth First Search |
|
Create a class called TestGraphAlgorithms that tests
classes DFS and BSF that implement your own reusable
version of Depth first search (DFS) and Breadth First Search (BFS),
respectively. These classes should be designed based on the Template Method
Pattern as described in your textbook for DFS. You may base your methods
on the code fragment provided in the text.
You will test your
DFS and BSF methods using the GraphAlgorithms class with a main() method that
performs the following actions:
-
For the graph shown above print the depth first and breadth first traversals of
this graph starting from A and I.
-
Perform the following action:
-
Create an UndirectedGraph, G,
with n=50 vertices, m=80 edges and seed=19.
-
Print the value of TestGraphAlgorithm.isConnected(G)
called on this graph
(i.e., print "true" or "false").
-
Perform the following action five (5) different times in a loop: Randomly pick
two different nodes, A and B, in the graph G and find/print the depth first search
and breadth first search paths between the nodes if it exists.
-
Perform the following action one hundred (100) different times in a loop:
Randomly pick two different nodes, A and B, in the graph G and find the length of
the depth first search path between the nodes if it exists. Print the average
length between these nodes.
-
Perform the following action one hundred (100) different times in a loop:
Randomly pick two different nodes, A and B, in the graph G and find the length of
the breadth first search path between the nodes if it exists. Print the average
length between these nodes.
-
Perform the following action five (5) different times in a loop:
-
Create an UndirectedGraph, G',
with n=100 vertices, m=2500 edges and seed = 116.
-
Print the value of TestGraphAlgorithm.isConnected(G)
called on this graph
(i.e., print "true" or "false").
-
Perform the following action one hundred (500) different times in a loop:
Randomly pick two nodes, A and B, in the graph G' and find the length of the depth
first search path between the nodes if it exists. Print the average length
between these nodes.
-
Perform the following action one hundred (500) different times in a loop:
Randomly pick two nodes, A and B, in the graph G' and find the length of the
breadth first search path between the nodes if it exists. Print the average
length between these nodes.
-
How does this number differ from the one in the proceeding experiment? What do
you think explains the difference?
Summary
- Create abstract classes DFS and BFS
- Create classes DFSOrder and BFSOrder that extends DFS and BFS,
respectively.
- Create classes DFSpath and BFSpath that extends DFS and BFS, respectively.
- Create class DFSisConnected that extends DFS
- Create class TestGraphAlgorithms.
- Do testing and experiments and write up the results