Week 3 - Homework

Using your programming language of choice develop a set of classes or functions that will allow to read in, store and perform certain calculations on graphs. With these classes or functions, you should then write a program that will read in a graph from a file, print out a representation of the graph and then do some calculations on the graph. Details follow:

Reading in Graphs

A graph will be provided in a text file in the form:
A B
A B
A D
A C
D B
D F
where each line represents an edge between two nodes. Note that node names are alphanumeric and of arbitrary length, and that there can be an arbitrary number of nodes and edges. Note that for this homework, you only need consider undirected graphs.

Representing Graphs

This is up to you, though if you're working in C++, Python or Java it would be good to have classes for nodes and edges. If you're working in C, you could use struct's. In any case, you'll want to implement methods or functions that will let you do things like

Calculations on Graphs

You should implement the following functions

You do not need to check for cycles or loops. Once you have these functions, write a program that reads in a graph specified in a file and then calls the functions for the graph that you read in and prints the output with an informative message. Implement the code yourself and do not use implementations from other libraries.

Evaluation

The homework is worth 40 points and the breakdown is as below To test your code, I've provided three graphs graph1.txt, smallworld.txt and estnodes.txt. I will test your code on some new graphs, so ensure that when you write the code, you can handle general cases and errors - that is, your program should not crash!.

Submitting

Tar or zip your source code and include a README indicating how the code should be compiled or run. Email it to me at rguha@indiana.edu.

The due date for this homework is 12th February

Rajarshi Guha
Last modified: Mon Jan 19 20:42:32 EST 2009