






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Write your name and Cornell netid above. There are 8 questions on 11 numbered pages. Check now that you have all the pages. Write your answers in the boxes provided. Use the back of the pages for workspace. Ambiguous answers will be considered incorrect. The exam is closed book and closed notes. Do not begin until instructed. You have 90 minutes. Good luck!
Score /15 /10 /20 /10 /15 /10 /5 /15 / Grader
//lo and hi are end points of the search interval in the array public static
(a) (5 points) If f (n) = O(n log n) and g(n) = O(n log n), prove that f (n) + g(n) = O(n log n). Argue in terms of witness pairs.
(b) (5 points) Sort the following in order of increasing asymptotic complexity: O(n log n), O(n^2 log n), O(n(log n)^2 ), O(n), O(1), O(nn), O(n^1.^618 ), O(1. 618 n), O(log n), O(2n).
Complexity Ordering Function From The List Above least complex 2 3 4 5 6 7 8 9
most complex
(c) (5 points) What is the asymptotic complexity of the following code fragment? Give justification.
int count = 0; for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { if ((j % 2) == 0) { for (int k=i; k<n; k++) count++; } else { for (int l=0; l<j; l++) count++; } } }
s s s s
s s s
s s s s