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 unionbyrank 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 unionbyrank 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
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
CS 170, Midterm #2, Fall 1999, SOLUTIONS
Problem #2
2) (25 points) Let p(x) = SUM_FROM_i=0_to_n (p_sub_i*x^i) and q(x) = SUM_FROM_i=0_to_m
(q_sub_i*x^i) be polynomials of degrees n and m, respectively, where n and m can be any integers such
that n>=m.
(a) Give an algorithm using the FFT that computes the coefficients of r(x) = p(x)_DOT_q(x). How
many arithmetic operations does it perform, as a function of m and n? Your answer can use O()
notation.
Answer: (1) Round up n+m+1 to the nearest power of 2, ie find the smallest k such that 2^k>=n+m+1:
k = CEILING_OF(LOGbase2(n + m + 1)). (2) Pad the vectors [p_sub_0,...,p_sub_n] and [q_sub_0,...,
q_sub_n] with enough zeroes to make vectors p_prime and q_prime of length 2^k. (3) Compute p_hat
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '02
 HENZINGER
 Computer Science, Complex number, Disjoint sets, Disjointset data structure

Click to edit the document details