{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Sample problem 3 in this problem you are not allowed

Info iconThis 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.
Background 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 ]}