Professional Documents
Culture Documents
asymptotic complexity.
4 marks:
2 marks: measure of cost of applying an algorithm
2 marks: approximation of computational complexity for very large data
2) Briefly describe the meaning of big-O, Θ, and OO notations (you do not need to
write the mathematical definition).
6 marks:
2 marks: big-O
2 marks: Θ
2 marks: OO
(2 marks for good explanation, 1 mark for some knowledge)
3) For one of the notations listed in Question (2), write the formal mathematical
definition.
2 marks: subtract half for small error, subtract 1 for semantic error
4) For each of the following pieces of code, write a function f(n) that indicates the
number of (assignment) operations the code will use based on the value of n, and
state the big-O complexity of the code.
f(n) = 2 + 2n = O(n)
1
for (int j = 1; j <= n; j++)
x += y[i][j];
5) Three different algorithms for solving the same problem have the following
complexity functions:
i. What are the big-O complexities of the 3 algorithms? (State the lowest upper
bound.)
1 mark each:
Alg. 1 is O(n log n)
Alg. 2 is O(n3)
Alg. 3 is O(n)
1 mark: True
1 mark: True
1 mark: False
1 mark: False
vi. Given a typical value for n of 100, which of the 3 algorithms would you
choose as the most efficient?
1 mark: Algorithm 1
2
3