A f 1 n g 1 n is o f 2 n g 2 n b f 1 n is o f 3 n c f

Info icon This preview shows pages 4–7. Sign up to view the full content.

View Full Document Right Arrow Icon
(a) f 1 ( n ) * g 1 ( n ) is O ( f 2 ( n ) * g 2 ( n )) (b) f 1 ( n ) is O ( f 3 ( n )) (c) f 3 ( n ) + g 3 ( n ) cannot be O ( f 1 ( n ) + g 1 ( n )) (d) log ( f 1 ( n )) is O ( log ( f 2 ( n ))) (e) f 1 ( n ) /g 1 ( n ) is O ( f 2 ( n ) /g 2 ( n )) 5. (30 pts) For each statement below, decide whether it is true or false. In each case attach a very brief explanation of your answer. (a) A binary heap of height 2 has at least 4 nodes and at most 7 nodes, true or false? (b) Suppose that the worst-case running time of method qq is Θ( n log n ) and the worst case running time of method uu is Θ( n 2 ). Then there is no input for which uu runs faster than qq , true or false? (c) It is possible to reverse the content of a stack using at most three other auxilliary stacks, true or false? 4
Image of page 4

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

View Full Document Right Arrow Icon
(d) A priority queue is a queue in which elements are enqueued in order of their priority, true or false? (e) Suppose we decide to change our model of computation (step-counting) by counting instructions that involve the creation of an array new int[n] as taking 10 n steps. In this new model, a program can have a different asymptotic complexity than in the original model, true or false? (f) In a binary min-heap with at least three elements the largest element is always in the right subtree of the root: true or false? (g) Suppose that f ( n ) is a function defined only for integers n 1 and that f ( n ) is O (1). Then, there exists a constant c 0 such that f ( n ) c 0 for all n 1, true or false? 6. A binary heap contains the keys 1 , 2 , . . . , 10 , 11. If we traverse it in postorder we list the keys as follows: 10 , 8 , 7 , 5 , 4 , 3 , 2 , 11 , 9 , 6 , 1. Draw the heap. 7. After a removeMin operation that returns the key a , a binary min-heap looks like this (the keys are ordered alphabetically): b / \ / \ / \ c f / \ / \ / \ / \ g d k i / \ / j h e Draw two different trees that could have been what the heap looked like before the removeMin operation. 8. Consider a binary heap of height h and let L be the number of nodes at depth h in this tree. Assuming that the tree has 1000 nodes, calculate h and L . 9. (15 points) In this problem you NOT allowed to use any of the theorems about Big-Oh stated in the lecture slides, the textbook, or the lab writeups. Your proof should rely only on the definition of Big-Oh. Prove that n 2 +3 n n is O ( n n ). 10. (15 points) Provide counterexamples for each of the following two false statements. You only need to give the counterexample, you don’t need to prove that it works. (As usual in this kind of problem, f ( n ) and g ( n ) map nonnegative reals to strictly positive reals.) (a) There is no f ( n ) such that f ( n ) is O (log n ) and f ( n ) is Ω(log n 2 ). 5
Image of page 5
(b) For any f ( n ) and g ( n ), if f ( n ) is O ( g ( n )) then 3 f ( n ) is O (3 g ( n ) ). 11. (20 points) static char[] too(char[] c) { int p = c.length; char[] d = new char[p*p]; for (int k = 0; k < p; k++) d[k*p]=c[k]*c[k]; return d; } static int foo(char[] a) { for (int i = a.length-1; i > 0; i--) a[i]=0; return a.length; } static void bar(char[] b) { for (int j = 1; j < foo(too(b)); j=2*j) b[j]=0; } Analyze the worst-case running time of bar(b) as a function of n = b.length and give a Big-Oh bound.
Image of page 6

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

View Full Document Right Arrow Icon
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern