Question 1:
Let $f(n)=n^3$ and $g(n) = 7n^3 + 5n^2 + 8n + 3$. Which of the following best expresses the relation between $f(n)$ and $g(n)$?
- $f(n)$ is $O(g(n))$
- $g(n)$ is $O(f(n))$
- Both A and B are true
- None of the above
Question 2:
We know that the runtime of an algorithm is $O(n^2)$. Then, for a fairly large input size, doubling the size of the input will have the following effect on the runtime:
- runtime will double
- runtime will quadruple
- runtime will be squared
- runtime will be unchanged
Question 3:
Consider the following code snippet:
for (int i=0; i<n; i++) {
for (int j=0; j<n/2; j++) {
offset1 = i*width + j;
offset2 = i*width + width-1-j;
for (int k=0; k<3; k++) {
swap(A, offset1+k, offset2+k);
}
}
}
The swap operation is executed:
- $O(n)$ times
- $O(n \log n)$ times
- $O(n^2)$ times
- $O(n^3)$ times
Question 4:
Consider the following code snippet:
stringList *s = new arrayStringList();
s->insertAtTail("hello");
s->insertAtTail("fish");
s->insertAtHead("pumpkin");
What is the content of the list?
- hello, fish, pumpkin
- pumpkin, hello, fish
- pumpkin, fish, hello
- fish, hello, pumpkin
- none of the above