cs320-2008-t2-sample-final-solution - CPSC 320 Sample Final...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CPSC 320 Sample Final Examination April 2009 [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. 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). [3] 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. [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. 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. [3] 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). [3] 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. [9] 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

Page1 / 7

cs320-2008-t2-sample-final-solution - CPSC 320 Sample Final...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online