# (d g n is not o f n true or false 38 consider the

This preview shows pages 11–14. Sign up to view the full content.

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (d) g ( n ) is not O ( f ( n )), true or false? 38. Consider the following statement: “ if f ( n ) and g ( n ) are positive functions and f ( n ) is O ( g ( n )) then n f ( n ) is O ( n g ( n ) ) ”. If the statement is true, prove it. If the statement is false, give a counterexample. 39. By adding to the code fragment below, describe in Java a method for multiplying an n × m matrix A and an m × p matrix B . Recall that the product C = AB is defined so that C [ i ][ j ] = m X k =1 A [ i ][ k ] B [ k ][ j ] . Then, give a Big-Oh upper bound on the running time of your method in terms of n,m,p . 11 double matmult(int n, int m, int p, double A, double B) { ... } 40. Define the function f ( n ) as follows: f ( n ) = 2 n when n is odd f ( n ) = 2 n/ 2 when n is even Is 2 n = O ( f ( n ))? Prove your answer. 41. Rewrite the following list of functions in increasing Big-Oh order: n √ n n 1 . 5 n log n n log log n n log 2 n n log( n 2 ) 2 n 2 n 2 n 2 37 n 3 n 2 log n (0 . 5) n 3 √ n 42. 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 if f ( n ) is O ( g ( n )) then 1000 f ( n ) is O (0 . 001 g ( n )). 43. Consider the following Java code fragment static double foo(double a, int k) { double sum = 0.0; for (int i = a.length-1; i > k-1; i--) sum = sum + a[i]; return sum; } static void bar(double b) { double c = new double[b.length-1]; for (int i = 0; i < b.length; i++) c[i] = foo(b,i); if (c.length == 1) System.out.println(c[0]); else bar(c); } Analyze the above code fragment and express the running times of foo and bar in Big-Oh notation. 12 44. For each statement below, decide whether it is true or false . Attach a very brief explanation. (a) Suppose program A runs in time Θ( n 2 ) and program B runs in time Θ( n 3 ). Then there is no input for which program B runs faster than program A , true or false? (b) Suppose we decide to make our JAVA model of computation “more realistic” by dividing JAVA instructions into easy and hard instructions where the easy ones cost 1 step and the hard ones cost 10 steps. A program can have a different asymptotic complexity in this new model of computation from its complexity in the original model, true or false? (c) gcd( x,y ) = gcd( x- y,y ) for all pairs of integers x and y , true or false? (d) Theoretical analysis of running time is useful in distinguishing between programs that are similar in their efficiency while empirical measurements can be used to distinguish between programs with widely different running times, true or false? 45. 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....
View Full Document

{[ snackBarMessage ]}

### Page11 / 14

(d g n is not O f n true or false 38 Consider the following...

This preview shows document pages 11 - 14. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online