CSCI 220: Project 4

Due date: Tuesday, December 16, 5 pm. No extensions!

NOTICE: Since we will have only 4 projects instead of the five originally stated in the syllabus, I will give you the choice of having each project count for 12.5 percent of your grade, or of having projects 1-3 count for 10 percent and this project count for 20 percent. I will count all projects equally unless you tell me otherwise.


Part I: Implementing a graph data structure

Implement a data structure to support the storage of an undirected graph and the following operations on it.

G=(V,E) is the graph

DIMACS Graph Format

DIMACS (Center for Discrete Mathematics and Theoretical Computer Science) has established a uniform graph format so researchers can easily share data. The format is as follows:
  1. The file begins with 0 or more comment lines. Each comment line begins with the letter 'c'.

  2. After any comment lines there will be a line with the number of vertices and edges in the graph. These lines are always of the format
    p edge #vertices #edges
    (This is to distinguish between other types of graphs used at DIMACS.)

  3. Following the line detailing the size of the graph there will be lines indicating edges in the graph. The lines are of the format
    e v u
    where e is the letter 'e' but v and u are integers representing the edge.

Here is an example graph in DIMACS format.


Part II: Breadth First Search

Implement Breadth First Search on a graph. Your Breadth First Search algorithm should take as input a graph and a vertex for the source. It should construct the BFS tree.

Write a program that reads in a graph and then constructs a Breadth First forest by repeatedly calling BFS (as we discussed in class). Output each of the trees level by level. For example:

source:  5
level 1: 2 4 8
level 2: 1 7 3
level 3: 6

The graph yielding the above tree is:

p edge 8 12
e 1 2
e 1 4
e 1 6
e 1 7
e 2 4
e 2 5
e 2 7
e 3 7
e 3 4
e 3 8
e 4 5
e 5 8

One way to store the resulting tree is to create a directed subgraph. This is a slight modification to your undirected graph data structure; if you use an adjacency list, only store out-edges in an adjacency list; if you use an adjacency matrix, only make M[v,u] = 1 instead of both M[v,u] and M[u,v].


Part III: Minimum Spanning Tree

Implement one of the minimum spanning tree algorithms discussed in class. The algorithm should be given a graph and should return a spanning tree.

You will need to modify your graph data structure to handle weighted graphs. The graph format is exactly the same except a third integer is added on each edge description line indicating the weight (cost) of the edge.

Write a program that reads in a weighted graph and outputs the minimum spanning tree of the graph.


IV: What to hand in

  1. Commented code detailing the data structures and algorithms.
  2. The main programs you used to test the data structures.
  3. Sample runs of the programs for parts II and III.

V: Test Data

I will generate some graphs for you; you should also make some small test graphs yourself. Hand in the runs of the program on the graphs I indicate are for benchmarks. (Watch this page for updates on where to get those graphs.)

Update: The directory /usr/local/www/data/csci220 contains 8 files of interest to you: