M.Sc. in High-Performance Computing 5613 - C programming Assignment 9 Rules

advertisement
M.Sc. in High-Performance Computing
5613 - C programming
Assignment 9
Mike Peardon ([email protected])
School of Mathematics, TCD
Rules
To submit, make a single tar-ball with all your code and a pdf of any written part you want to
include. Submit this via msc.tchpc.tcd.ie by Friday January 22nd. Attempt all parts. This
assignment is worth 20 marks. Marks will be given for the efficiency of your implementation.
Late submissions without prior arrangement or a valid explanation will result in reduced marks.
Question
A graph is a set of NV vertices and NE edges which link pairs of vertices. A graph can be stored
in a simple file format by listing each vertex along with all the vertices it is directly connected
to by an edge. An example is given in the figure below.
1
3
File representation:
0
6
4
2
0;1;2;4
1;0
2;0;4
3;4;6
4;0;2;3;5
5;4;6
6;3;5
5
Write a program to read data from a file (with the file-name specified on the command line)
and print to the terminal the number of connected sub-graphs and for each connected subgraph, print a histogram of the number of pairs of vertices that are a distance d apart. Example
output for the graph in the figure above is:
Number of connected sub-graphs: 1
Distance | Number of node-pairs
1
8
2
8
3
4
4
1
Download