Assignment 6

Due Wednesday, 3/6/96. Turn in all of the following problems:
  1. Show the data structure results and answers printed before and after each find operation in the programs below:
    for i := 1 to 16 do
       MakeSet(i);
    for i := 1 to 15 by 2 do
       Union(i,i+1);
    for i := 2 to 14 by 4 do
       Union(i,i+2);
    Union(4,8);
    Union(12,16);
    Union(8,16);
    writeln(Find(2));
    writeln(Find(9))
    
  2. Write an algorithm to determine the collection of connected components of G. (The algorithm should be in the same style as in the text.)
  3. Program Kruskal's algorithm to find the minimum cost spanning tree of a connected graph. The input to the algorithm should be as follows: On the first line, put the number of edges, e, in the graph. On each of the following e lines, list the two vertices of an edge. followed by its cost (an integer). The order of the edges should be irrelevant. For example, here is the input for a simple graph with 4 edges:
    4
    1 3  5
    1 2  3
    3 2  1
    4 1  3
    
    You may write your program in C, C++, Pascal, or Object Pascal. If your program is designed to run on the Suns, use the "turnin" program to submit it. If it is designed to run on the Macs, put it in the dropoff folder on Cider Press for CS256.

    Your program should use the most efficient data structures discussed in class and run as quickly as possible.