CS 400/600:
Data Structures and Software Design

Project 3: Minimal Spanning Trees

Due: Aug 4, 1999 11:59PM    Summer Qtr 1999,   pmateti@cs.wright.edu

Feel free to use the source code files from the web site (http://www.cise.ufl.edu/~sahni/dsac) of the author of our textbook. Make adaptations, and further assumptions as necessary, but must be documented. Do not use source code obtained from other sources unless you have received prior consent from me. I will answer questions relating to P3 in our newsgroup. Keep an eye on the newsgroup wright.cs.400.

We wish to compare the run-time performance of Prim, Kruskal and Sollin's algorithms (Section 13.3.6 of Sahni's book) by actually running the algorithms on a series of weighted undirected graphs that are randomly generated. The number of trees to be generated is given as an argument to your program. Name this program compareMST. The program is then required to output for each graph G considered (1) a string representation of G, (2) a measure of time consumed (as in the prvious project) by each of the algorithms, and (3) a string representation of the min spanning tree found by each of the two algorithms.

Design



class Graph {
  public:
    Graph (int n);
    ~Graph();

    String toString();

    int isConnected();
    int isTree();
    int totalWeight();

    Graph Kruskal();
    Graph Prim();
}

Design and implement this class. Your class for Graph need not be identical to this, but should have all the essential features shown here.
  1. Its constructor should take n, the number of vertices as an argument, and randomly generate an undirected weighted graph of n vertices.
  2. The method int isConnected() returns 1 if this graph is connected, 0 otherwise.
  3. The method int isTree() returns 1 if this graph is a tree, 0 otherwise. The method int totalWeight() returns the sum of the weights of all the edges of this graph.
  4. The method String toString() returns a printable text string of the graph. This may be a string consisting of several lines. If the graph has an edge connecting vertices a and b with a weight of w, the text representation of this edge is a-b:w where a, b and w are all in decimal notation. Here is an example:

    vertices = 3; edges = 3; total = 104; 1-2:5, 2-3:4, 1-3:95.

  5. The rest of the details of this class you should be able to develop.


Turnin

Submit your solution electronically using turnin P3 <files>. It should include a Makefile, the source code files, and test input files of your choice, and their output files, a ReadMe.txt file, and a successfully run typescript file of test results of at least 10 graphs, We may make and test your program.

http://www.cs.wright.edu/people/faculty/pmateti/