This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CPSC 320 Sample Final Examination April 2009  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. What factor(s) does the average-case running time of SkipListSearch on a given skip list (averaged over all keys one could search for) depend on? Solution : It depends only on the levels of the nodes in the skip list (in other words, it does not depend on the order of insertion, or on whether or not nodes were deleted at some point).  b. True or false: for small values of n (for instance n ≤ 800 or so), algorithm DeterministicSelect is slower than the naive O ( n log n ) algorithm (the one that sorts the array using quicksort or mergesort, and then returns the requested element in constant time). Solution : This is true. The constant hidden by the O notation for algorithm DeterministicSelect is very large.  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. Name one reason why the choice of a random level for each node in a Skip List helps us achieve a good average case running time. page 2 Solution : Because we end up with approximately 1 /p more nodes on level i − 1 than we had on level i , and these nodes are more or less evenly distributed between the nodes on the level i list.  e. What is the main difference, in terms of the running time of their operations, between a binomial heap and a Fibonacci heap? Solution : Every operation on a binomial heap runs in O (log n ) worst-case time. Most operations on a Fibonacci heap run in O (1) time (amortized, for decrease-key ), while extract-min and delete run in O (log n ) amortized time (with a Θ( n ) worst-case time).  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. In class (or in previous courses you took), we learned about the following algorithms, all of which take an array A as parameter. (a) DeterministicSelect (b) Heapsort (c) Insertion sort (d) RandomizedQuicksort (e) RandomizedQuickSelect (f) Quicksort For each of the statements below, list all of the algorithms listed above for which the statement is true (you do not need to justify your answer(s))....
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