{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs320-2008-t2-sample-final-solution

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

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

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 0 = 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.

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

View Full Document
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)).
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern