CS302 Midterm Exam - October 14, 2014

Do your answers on the answer sheets provided. When you write code, you do not need to have "include" or "using" statements.

Question 1

For each of the following, tell me the running time. Use the answer sheet. For disjoint sets, assume that you are using union by rank with path compression. Assume that m is smaller than n. If two answers are correct, please give me the one that is smaller -- in other words, if something is O(n) and also O(n2), then the answer should be O(n). Choose from the following multiple choice answers:

a. O(1) g. O(n) m. O(m log(n)) s. O(nm) y. O(2m)
b. O(α(m)) h. O(n α(n)) n. O(m log(m)) t. O(mn) z. O(2n)
c. O(α(n)) i. O(m α(n)) o. O(n log(n)) u. O(mm)
d. O(log(n)) j. O(m α(m)) p. O(nm) v. O(nn)
e. O(log(m)) k. O(n α(n)) q. O(n2) w. O(n!)
f. O(m) l. O(n log(m)) r. O(m2) x. O(m!)

Question 2

To the right is an instance of disjoint sets. Answer the following. For each question, assume that the starting state is as pictured. Do not have the state of the instance change as you answer questions.

  • A. What does Find(0) return?
  • B. What does Find(1) return?
  • C. What does Find(2) return?
  • D. What does Find(3) return?
  • E. Suppose we call Union(6, 10) and we are using Union By Size. Specify the links vector that after the union call.
  • F. Suppose we call Union(6, 10) and we are using Union By Height. Specify the links vector that after the union call.
  • G. Suppose we call Find(12) and we are using path compression. Tell me which elements of links change, and what they change to.