This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 3. Sort the following running times so that f ( n ) is left from g ( n ) if f ( n ) is O ( g ( n )), indicating whether any two are Θ to each other. No proof required. n √ n,n log n, 1 . 5 n ,n 2 , 2 n 2 , log( n 2 ) n 4. Given that f 1 ( n ) is O ( f 2 ( n )), f 2 ( n ) is O ( f 3 ( n )), g 1 ( n ) is O ( g 2 ( n )), and g 2 ( n ) is O ( g 3 ( n )), state whether the following statements are true or false. If true, no proof is required. If false, give a counterexample. (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 worstcase 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 (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 (stepcounting) 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 minheap 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 such that f ( n ) ≤ c 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 minheap 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 BigOh stated in the lecture slides, the textbook, or the lab writeups. Your proof should rely only on the definition of BigOh....
View
Full Document
 Spring '09
 TANNEN
 Algorithms, Data Structures, Big O notation, Analysis of algorithms, Binary heap, Tree traversal, static int foo

Click to edit the document details