Sample problem 3 in this problem you are not allowed

Info icon This preview shows pages 2–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Sample Problem 3 In this problem you are NOT allowed to use the theorems about Big-Oh stated in the lecture notes. Your proof should follow just from the definition of Big-Oh. Let f ( n ) = 1 10 n n and g ( n ) = 100 n + 1000 Prove that f ( n ) is not O ( g ( n )). Answer Proof by contradiction. Suppose that f ( n ) is O ( g ( n )), i.e., N, c > 0 such that n N we have 1 10 n n c (100 n + 1000) First we transform a bit the last inequality into an equivalent one: 1 10 n n c (100 n + 1000) iff n n 1000 cn + 10000 c iff n ( n - 1000 c ) 10000 c This last inequality is contradicted if n > 1 and n - 1000 c > 10000 c , that is n > 11000 2 c 2 . Therefore the statement n N 1 10 n n c (100 n + 1000) is contradicted by taking n = max( N, 1 , 11000 2 c 2 ) (The reason we have 1 there is because our def of BigOh does not require N, c > 1.) Sample Problem 4 Analyze the following fragment of code and give a Big-Oh characterization of its running time (that is, give the best upper bound on the worst-case running time of the algorithm that you can find). Explain your analysis. public static void doWork (int[] arr) { for (int i=1; i < 10; i++) { for (int j=0; j < 3*i; j++) { for (int k=0; k < arr.length; k++) { System.out.print(i+j+k); } } } Answer Let n = arr . length be the size of the input.
Image of page 2

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

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