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
- See if there is an edge containing a specified node
- Check whether a node exists
- Get the edge containing the two nodes
- Count the number of edges connected to a node (i.e., vertex
degree)
Calculations on Graphs
You should implement the following functions
- getAdjacencyMatrix - returns an adjacency matrix for the
graph
- getDistanceMatrix - return a matrix whose (i,j) element
is the shortest topological distance between nodes i and j. To implement this you'll need to implement
the Floyd-Warshall
algorithm (assume that edge costs are 1).
- getClusteringCoefficient - return the clustering
coefficient for a given node. Use it to calculate the average
clustering coefficient for the graph. See class notes or the
Wikipedia page
- getDegreeCentrality - return the degree centrality of the
graph (consider using the adjacency matrix)
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
- 20 - Implementing the above requirements
- 15 - Correctness of the output on new graphs
- 5 - Cleanliness of the code, comments, capturing edge
cases
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