Tutorial 01
Tutorial 01
Tutorial 01
Question 1. Find the tight Big-Oh notations for the following functions.
(You do not need to provide the details of how you obtained the Big-Oh
notations.)
1.1 f (n) = 5n
1.3 f (n) = 2n
1.4 f (n) = 3n
1.5 f (n) = n3
√
1.6 f (n) = n
1.14 f (n) = 5n + n2
1
Question 2. For this question, you do not need to provide the details of
how you obtained the Big-Oh notations.
2.1 f (n) = O(n3 ), g(n) = O(n3 ), what is the tight Big-Oh notation of
f (n) + g(n)?
2.2 f (n) = O(n3 ), g(n) = O(n2 ), what is the tight Big-Oh notation of
f (n) + g(n)?
2.3 f (n) = O(n3 ), g(n) = O(nlog(n)), what is the tight Big-Oh notation of
f (n) + g(n)?
2.4 f (n) = O(n3 ), g(n) = O(2n ), what is the tight Big-Oh notation of
f (n) + g(n)?
Question 3. For this question, you do not need to provide the details of
how you obtained the Big-Oh notations.
3.1 f (n) = O(n3 ), g(n) = O(n2 ), what is the tight Big-Oh notation of
f (n)g(n)?
3.2 f (n) = O(n3 ), g(n) = O(2n ), what is the tight big-Oh notation of
f (n)g(n)?
Question 5. What are the tight Big-Oh notations of the running time of
the following Python codes?
5.1 s = 0
for i in range(n):
s = s+i
Note that in Python, “for i in range(n)” means “for i from 0 to n-1, the
increment of i is 1 after each iteration”.
5.2 p = 1
for i in range(n):
p = p*2
5.3 p = 1
for i in range(n**2):
p = p * 3
2
5.4 s = 0
for i in range(2*n):
for j in range(i):
s = s + i
Question 6. What are the tight big-Oh notations of the running time of
the following Python codes?
6.1 i = 0
j = 0
s = 0
for i in range(n):
j = 0
while j < n:
j = j + 1
s = s + 3
6.2 i = 0
j = 0
s = 0
for i in range(n):
while j < n:
j = j + 1
s = s + 3