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 [10] 1. Answer each of the following questions with true or false . Give a short justification for each of your answers. [5] 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 ). [5] 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. [18] 2. Short Answers [3] a. Why is it important to know that a problem is NPComplete? Solution : Because then we know not to waste time trying to find an efficient algorithm for it that always returns the correct answer. [3] 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. [3] 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. [3] d. The PrimJarn´ ı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. [3] e. Why does the GaleShapley (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. [3] f. When do we use amortized analysis? Solution : When we are trying to prove a good upperbound on the worst case running time of a sequence of n operations. [9] 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 worstcase 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
 Fall '10
 Karen
 Analysis of algorithms, Recurrence relation, Dominating set

Click to edit the document details