h1 - 1 COMPSCI 225-002 Intro. to CS II (Fall 2011) Homework...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 COMPSCI 225-002 Intro. to CS II (Fall 2011) Homework #1 (80 points), due on 9/22/2011, Thursday Q1(18 points): Running Time Analysis. (a)(9 points) For the following functions f , please ±nd the tight (as good as possible) upper bounds in the order hierarchy, i.e., ±nd the tightest big-oh notations. (i) f ( n ) = log( n 10 ) + n (ii) f ( n ) = n 3 + 1000 n 2 (iii) f ( n ) = n 100 + 2 n . (b)(9 points) Give the running time big-oh notations for the following codes in terms of n . (i) int sum = 0; for (int i = 0; i < n; i++) sum = sum +i; for (int j = 0; j < n; j++) sum--; (ii) int sum = 0; while (n > 0) { sum += n; n = n-2; } (iii) int sum = 0; for (int i = 0; i < n; i++) for (int j = 0; j < 10; j++) sum++;
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Q2(10 points): Exception Handling. try { int count = 0, total = 0, num; double average; BufferedReader in = new BufferedReader(new FileReader("input.txt")); while ((numStr = in.readLine()) != null) { count++; num = Integer.parseInt(numStr); total += num; } average = total / count;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

h1 - 1 COMPSCI 225-002 Intro. to CS II (Fall 2011) Homework...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online