This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CPSC 320 Sample Final Examination December 2010  1. Answer each of the following questions with true or false . Give a short justification for each of your answers.  a. 6 n ∈ O (5 n ) Solution : This is false: lim n → + ∞ 6 n 5 n = lim n →∞ parenleftbigg 6 5 parenrightbigg n = + ∞ which means that 6 n ∈ ω (5 n ). Therefore 6 n / ∈ O (5 n ).  b. 1 . 5 n + n 2 ∈ O (1 . 5 n + n log n ) Solution : This is true, since for n ≥ 13 we have n 2 < 1 . 5 n , which means that 1 . 5 n + n 2 ≤ 1 . 5 n + 1 . 5 n = 2 · 1 . 5 n < 2 · (1 . 5 n + n log n ). Hence take c = 2 and n = 13.  2. Short Answers  a. Why is it important to know that a problem is NP-Complete? Solution : Because then we know not to waste time trying to find an efficient algorithm for it that always returns the correct answer.  b. Explain why the following statement holds: “Finding the median of an un- ordered array is as difficult as finding the i th order statistics of that ar- ray, for an arbitrary i ”. Hint: think of the implementations of algorithm RandomizedQuickSelect Solution : In order to find the median of the array, we will most likely end up trying to find the i th smallest element of a subset of m elements, where i negationslash = ⌈ m/ 2 ⌉ . In that sense, in order to be able to find the median, we need to be able to find an arbitrary order statistics. Thus finding the median is not any easier.  c. What is the main advantage of RandomizedQuickSelect over Select1 ? Solution : RandomizedQuickSelect performs well on average on every pos- sible input, whereas Select1 performs very well (always) on some inputs, and very badly (always) on other inputs.  d. The Prim-Jarn´ ık algorithm associates a cost with each vertex that has not yet been added to the tree it constructs. What does this cost represent? page 2 Solution : It represents the cost of the cheapest edge that connects the ver- tex to the part of the minimum spanning tree that has already been con- structed.  e. Why does the Gale-Shapley (Stable Matching) algorithm discussed in class terminate after at most n 2 iterations? Solution : Because at every step a woman proposes to a man she has never proposed to. There are only n 2 possible couples, and hence the loop could not iterate more than n 2 times without repeating a proposal.  f. When do we use amortized analysis? Solution : When we are trying to prove a good upper-bound on the worst- case running time of a sequence of n operations.  3. A Computer Science researcher has designed a new data structure called a sheap that supports operations insert , findMinMax and extractMinMax , and decides to use amortized analysis to determine the worst-case running time of a sequence of n operations on an initially empty sheap. She defines a potential function Φ for sheaps,operations on an initially empty sheap....
View Full Document
This note was uploaded on 10/09/2011 for the course CPSC 344 taught by Professor Karen during the Fall '10 term at UBC.
- Fall '10