CS302 Midterm Exam - October 13, 2015 - Page Four


Question 5

On the answer sheet provided, implement the constructor, Union() and Find() operations of Disjoint Sets. You may implement any of the three options that I described in class. When you're done, in the space provided, specify which option that you implemented, and what the running times of all three operations are. I don't care which option you implement, and there is no bonus or penalty for one option over another.

Question 6

Write a recursive function with the following prototype:
long long two_ks(int K, long long S);
This function should return the value 2K%S, and it should run in time O(log(K)). You may find the following two observations very useful: