37 suppose 0 f n g n for all n 1000 for each of the

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

View Full Document Right Arrow Icon
37. Suppose 0 < f ( n ) < g ( n ) for all n > 1000. For each of the following, if true, give a very brief justification, if false, give a very brief counterexample. (a) f ( n ) is O ( g ( n )), true or false? (b) g ( n ) - f ( n ) is O ( f ( n )), true or false? (c) f ( n ) + g ( n ) is O ( g ( n )), true or false? (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
Image of page 11

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

View Full Document Right Arrow Icon
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
Image of page 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.
Image of page 13

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

View Full Document Right Arrow Icon
Image of page 14
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