(Latest Revision: 02/29/2000)
02/29/2000: clarified directions on spanning tree program

CS 4440 Work Assignment:
Weeks One to Two


Assignments for weeks #1-2 of Theory of Algorithms

Reading to be finished by Friday 03/03/2000:

* chapter 6 up to p. 192
* section 5.9 (pp. 175-180)
* the rest of chapter 6
* pp. 1-35

Homework to be turned in at the start of class 03/07/2000:

Do the following problems in the text book:

5.32 (write the procedure.  the "proof" is optional.)
6.2, 6.3, 6.8.

Also, code up a version of the algorithm on page 195 in (a
dialect of) C or Pascal.  Write the program to read the
following kind of input from stdin:

=========================
7           /* number of nodes */
1 2 1       /* two edge ends, then weight given last */
2 3 2
4 5 3
6 7 3
1 4 4
2 5 4
4 7 4
3 5 5
2 4 6
3 6 6
5 7 7
5 6 8
=========================

Thus, the input gives first the number of nodes in the graph,
then a list of edges and edge weights, in order by
non-decreasing weight, in the format:
(one end, other end, weight)

As output, have the program echo the input, then output the
edges of a minimum weight spanning tree, and lastly output the
total weight of the tree.  The format of the edges output
should be just like the input.  Thus the output corresponding
to the input above would be something like:

=========================
The graph is:

7           
1 2 1       
2 3 2
4 5 3
6 7 3
1 4 4
2 5 4
4 7 4
3 5 5
2 4 6
3 6 6
5 7 7
5 6 8

A minimum weight spanning tree is:

1 2 1
2 3 2
4 5 3
6 7 3
1 4 4
4 7 4

Total weight: 17
=========================

If you like, you can assume that the number of nodes cannot
exceed 10, and that the number of edges cannot exceed 45.

Since the input is sorted by edge cost, your algorithm is not
required to include a step that sorts the edges.

However, I do want you to make some test input.  Create at least
one interesting graph of your own, and feed a sorted list of its
edges to your algorithm to test it.  Also do a test run using the
sample input above.

All other things being equal, I'd prefer that you implement the
most efficient version of the union-find data structure, but if
you want to use a less sophisticated version that is permissible.

e-mail me a copy of the source code for your program, and turn in
printouts of the test runs.

(This problems is designed to help you master the details of
Kruskal's algorithm, as well as the "union-find" problem of
section 5.9.  Efficient union-find procedures are key pieces of
*many* advanced algorithms.  For another example, look at the
schedule-building algorithm on page 214.)