Questions 1-3 pertain to the following program, which takes an integer
n on the command line.
main(int argc, char **argv)
{
int n, i, k;
int total;
if (argc != 2) exit(1);
n = atoi(argv[1]);
if (n < 0) exit(1);
total = -20;
for (i = 0; i <= n; i++) {
total++;
for (k = n; k > 1; k = k / 2) {
total++;
}
}
printf("%d\n", total);
}
|
Question 1 (2 points)What does the program print out when n is 4? Write your answer on the answer sheet.
Question 2 (4 points)Exactly what does the program print out as a function of n? (e.g. it prints out 2n, or 5n*n - 40). If you want, you may assume that n is a power of two. |
Question 3 (9 points)Look at the table on the answer sheet.Let the output of the program be f(n). Each column of the table is a different function g(n). There are four rows, one each for O(g(n)), Omega(g(n)), Theta(g(n)), and o(g(n)). Your job is to put an X in the each entry of the table where g(n) is has the proper relationship to f(n). For example, consider the first column, where g(n) = 1.
| |