CS 170, Midterm #2, Fall 1999, SOLUTIONS
CS 170, Fall 1999
Midterm 2 with Solutions
Professor Demmel
Problem #1
1) (15 points) The following is a forest formed after some number of UNIONs and FINDs, starting with
the disjoint sets A,B,C,D, E, F, G, H, and I. Both union-by-rank and path compression were used.
(a) Starting with the forest above, we now call the following routines in order:
FIND(B), UNION (G,H), UNION (A,G), UNION (E,I)
Draw the resulting forest, using both union-by-rank and path compression. In case of tie during
UNION, assume that UNION will put the lexicographically first letter as root:
Answer:
(b) Starting with the disjoint sets A, B, C, D, E, F, G, H, and I, give a sequence of UNIONs and FINDs
that results in the forest shown at the top of the page. In case of a tie during union, assume that UNION
will put the lexicographically first letter as a root.
Answer: One solution is
UNION (F,G), UNION (A,C), UNION (B,E), UNION (B,D), UNION (D,A)
file:///C|/Documents%20and%20Settings/Jason%20Raft.
..-%20Fall%201999%20-%20Demmel%20-%20Midterm%202.htm (1 of 4)1/27/2007 5:30:44 PM