Assignment #7
CS160
DUE : Monday 12/13.
Implement Kruskal's algorithm as described in the text, pages 353-355 (this is problem 9.18). This requires putting together several ingredients:
- The pseudocode for the algorithm, outlined in class.
- Implementation of graphs and their associated edges (best done
as classes).
- Storage of the weighted edges on a
heap.
- Using the
disjoint set data type (union/find algorithms)
to detect cycles.
Implement your graphs so that they can be read in from a file. Nodes can be specified by letter or number (your choice). One possible format for the file would be to make each line represent an edge, as
node1 node2 weight
for example,
A B 3
A D 4
A E 4
.....
would indicate that node A is adjacent to B, D and E, and that the weight of edge (A,B) is 3, that of (A,D) is 4, and (A,E) is 4 as well.
Run the algorithm on the graph of figure 9.82 and check that your answer is correct by hand.
The output should be a reasonably readable representation of the
minimum spanning tree. An indented form showing internal nodes of the
tree, using indentation to indicate descendant nodes, is preferable.
Back to
CS160 Home Page