CS 302 - Data Structures & Algorithms - Spring 2008
Programming Assignment 5


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

His and Hers Graph Algorithms

Due

Design and Test Cases: Friday, April 11
Code, etc.: Friday, April 18 in 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 can be represented using an adjacency matrix or adjacency list. This project investigates these two as an example of a classic time/space trade-off. Write two programs: graph-gen and graph-stats. The program graph-gen should output the vertices and then the edges of an undirected graph. For example, K=3 would be output as (The first line in the vertex count. The "-1" lines are sentinels.)
3
A
B
C
-1
A B
A C
B C
-1 -1
You can assume that the vertex names are no more than 255 characters and contain no white space.

Assignment

Implement the Euclidean Neighbor algorithm in graph-gen where vertices are associated with random points in the box defined by 0,0 and 1,1. Then use it to generate multiple graphs having 1000 and 10,000 vertices. For each graph connect pairs of points that are no further than the following distances: 0.1, 0.3, 0.5, 0.7, and 0.9.

Then implement graph-stats, which reads in a graph from stdin and outputs various stats about the graph. It should take as a command line argument the switch -list if an adjacency list representation is to be used and -matrix (the default) if the adjacency matrix representation is to be used. For each of the ten graphs generated by graph-gen output the following:
  1. number of vertices
  2. number of edges
  3. vertex with the most incident edges
  4. the time taken to initialize the graph (pre reading)
  5. the time taken to read the graph
  6. the time taken to process the graph
  7. the memory foot-print of your program right before termination.

Finally, create a 1-2 page well laid out summary report explaining the data (include some nice looking graphs).

What to hand in

  1. (by 4/11) A one-page design.
  2. (by 4/11) A black-box test plan.
  3. (on 4/18) A two-up well-formatted listing of your code. You might use something like
    a2ps -T 4 -q -Avirtual -2 -o mycode.ps <file>
    and then preview the page breaks and general appearance using gv mycode.ps
  4. (on 4/18) Your summary report.
  5. (on 4/18) Email me a single tar file that includes

Notes

  1. You need your time to be as precise as possible. Man ctime to find out more.
  2. The following code will give you the memory footprint of a process
    #define SM_BUFF_SIZE_PI 100
    
    int getProcessSize() {
      char buffer[SM_BUFF_SIZE_PI];
      int memSize;
      FILE *fileStream;
      pid_t id = getpid();
    
      // Command to execute - uses ps to get the current size and finds the              
      // size for the particular process                                                 
      sprintf(buffer, "ps -eo vsz,vsize,pid | grep %d | ", id);
      strcat(buffer, " awk '{printf(\"%s\\n\", $1);}'");
    
      // Creates a process to get the information and write the result to a              
      // file stream                                                                     
      fileStream = popen(buffer, "r");
      fscanf(fileStream, "%d", &memSize);
      fclose(fileStream);
      return memSize;
    }