These are the multiple choice questions. Please, try to understand why the answer is what it is. If you are stuck, ask in the comments.
- Which of the following are not O(n2). Answer: n3/sqrt(n)
- (1510) * n + 12099
- n1.98
- n3/sqrt(n)
- 220 * n
- Sort the functions by increasing order of complexity. Answer: f3, f2, f4, f1
- f1(n) = 2n
- f2(n) = n3/2
- f3(n) = n log n
- f4(n) = nlog n
- Which of the following loops is the fastest? Assume the same code inside the loops. Also assume
n
is a positive integer. Answer:for (idx = 1; idx < n; idx *= 2)
for (idx = 0; idx < n; ++idx)
for (idx = 0; idx < n; idx += 2)
for (idx = 1; idx < n; idx *= 2)
for (idx = n; idx > -1; idx /= 2)