CS 302 - Data Structures & Algorithms - Spring 2005

Programming Assignment 3

 


Loyola College > Department of Computer Science > CS 302 > Programming Assigngments > Programming Assignment 3


Matrix and List Representations of Graphs

Due

Wednesday, March 16th at 11:59pm.
Turn in a print out of the assignment Friday, March 18th at the beginning of class. Be sure to include the Honor Code Statement:
"I hereby declare that I have abided by the Honor Code during this assignment."

Introduction

Graphs are complex structures that describe relationships between entities. We have learned about two different ways to storing the information necessary to describe a graph. One method is to create an adjacency matrix that records the presence or absence of an edge between two vertices by using the vertex indices to locate a particular element in the matrix and set the value to true. Another way of representing the graph is to use an adjacency list where all the vertices adjacent to a given vertex are listed in a linked list. These two different representations involve a trade-off between space and time. In this project we will investigate this trade-off.

Assignment

  1. Complete the implementation of the SparseGraph class by implementing the methods remove and edge. Also add a destructor and copy constructor to the class.
  2. Add documentation to the DenseGraph and the SparseGraph. At the very least, each method should be described and a description of the parameters and return value should be included.
  3. Add a method to GraphIO that writes the edges that fall in the upper triangle of the matrix as pairs of numbers to a file stream, which is passed to the method as a parameter.
  4. The class GenRandomGraph contains numerous methods for generating random graphs. All of which are discussed in Section 17.6 of the text. Add an implementation for creating a Euclidean neighbor graph as described on page 49.
  5. Generate multiple graphs using the Euclidean neighbor generator. You should create graphs with 100, 1000, and 10,000 vertices. For each of these graph sizes, create graphs where the distance is .1, .3, .5, .7, and .9. Write these to a file you the new method you added to GraphIO.  You should create multiple graphs for each number of vertices and distance combination.
  6. For each random graph generated, you will read the file containing the vertex pairs to create a dense and a sparse representation of the graph. To create an instance of the graph, read the file of edges and store it in a vector (Use the reserve function to set aside enough space to store all the edges). Then you can begin collecting data about this graph. Determine the amount of time it takes to
    1. Initialize and insert all the edges into the graph
    2. Call the method edge on all pairs of vertices

In order to find the execution time, you need to record the system clock using the times method discussed in processInfo.h. Once you have the recorded times, the method timeInterval will compute the time between the two times. You will also determine the amount of space required by the program to store the graph in memory. Use the function getProcessSize which is also in processInfo.h to find the current size. To summarize your program will need to output the number of edges, the time to build the graph, the time to find all edges, and size of the memory foot print. You may also want the program to print other information such as the number of vertices and/or the type of graph so you can write all the data to a few files and then input it into a spreadsheet to produce visualizations of the data. Use this data to create 9 visualizations (i.e. graphs), one for each number of vertices / time or space pairs. The graph will illustrate how the performance changes as the number of edges change.

Extra Credit

  1. (20 points) Create an inherited version of the Graph classes where Graph and Graph::AdjIterator are abstract classes and the data fields that all graphs need are protected and part of the Graph class. SparseGraph and DenseGraph will be derived classes. Provide a method getType which will identify the specific subclass stored in a Graph*. Graph pointers can hold any type of Graph, but you will not be able to declare Graph G; because Graph is an abstract class. The same is true for Graph::AdjIterator. Modify the class GraphIO so that it is no longer a templated class. Its methods should take a Graph as a parameter. Rewrite the method show so it works properly with the inherited version of the Graph classes. Submit this modification separately from the code for the assignment.
  2. (15 points) Choose one of the other random graph generators, excluding the deBruijn Graph, to create and rerun the experiment. Speculate on the reason for any differences you observe in the performance between the Euclidean neighbor generator and the generator you chose.

Supplied Source Code

Graph.h
DenseGraph.h
AdjIteratorDG.h
SparseGraph.h
SparseAdjIterator.h
GraphIO.h
GenRandomGraph.h
processInfo.h
This code is also available in the /cs302/code/pa3 on peanuts

Submission