Questions 08-13
CS140 Final Exam: May 10, 1999

The following code fragments are for questions 8-13.
Assume that i, j, and n are all integers.

(a)

for (i = 0; i < n*n; i++) {
  printf("\n");
}
(b)

for (i = 0; i < n; i += 5) {
  printf("\n");
}
(c)

for (i = 1; i < n; i *= 2) {
  printf("\n");
}
(d)

for (i = 1; i < n; i *= 2) {
  for (j = 3; j < 4n+5 ; j++) {
    printf("\n");
  }
}
(e)

for (i = 1; i < n; i ++) {
  for (j = 4n; j > 0; j--) {
    printf("\n");
  }
}
(f)

for (i = 0; i < n*n; i += n) {
  for (j = i; j < i+n ; j++) {
    printf("\n");
  }
}

Circle all answers that apply.

Question 8: Which of the above print out O(log(n)) lines?
Question 9: Which of the above print out O(n) lines?
Question 10: Which of the above print out O(n*log(n)) lines?
Question 11: Which of the above print out O(n*n) lines?
Question 12: Which of the above print out Theta(n) lines?
Question 13: Which of the above print out Omega(n*n) lines?