Suppose f n is o g n prove that f n 100 n is o g n n

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

View Full Document Right Arrow Icon
Suppose F ( n ) is O ( G ( n )). Prove that F ( n ) + 100 n is O ( G ( n ) + n ). 46. Consider the following Java code fragment static void swap( int[] a, int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } static int foo( int j, int i) { int r = 1; for (int k = j; k < i; k++) r = (r * k) % 100 ; return r; } static void bar(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[ i ] = i+1; for (int i = 1; i < n; i++ ) swap( a, i, foo( 0, i) ); } Analyze the running time of bar in Big-Oh notation. 13
Image of page 13

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

View Full Document Right Arrow Icon
47. 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 2 n +1 is O (2 n ). 48. Consider the following code fragment for computing the nth Fibonacci number, F n . Let C ( n ) be the number of recursive calls made by this fragment when the input is n . Show that C ( n ) = C ( n - 1) + C ( n - 2) + 1. Prove using induction that C ( n ) > F n . public static long fib (int n) { if (n <= 1) return n; else return fib(n-1) + fib(n-2); } 49. Which of the following statements are true: (a) O ( n 3 + n 2 + n ) is the same as O ( n 2 ). (b) O (10 10 ) is different from O (1). (c) The running time of an algorithm depends on the underlying model of computation. (d) The worst-case running time of the following code fragment is O ( n 2 ): int x = 0; for (int i = 0; i < n; i++) if (false) for (int j = 0; j < i; j++) x++; 14
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