0% found this document useful (0 votes)
32 views

Tutorial 01

This document contains an algorithms tutorial with questions about determining the tight Big-O notation for various functions and Python code snippets. It asks the student to find the Big-O of single functions, sums of functions, products of functions, and the time complexity of basic for and while loops in Python code.

Uploaded by

sanjena1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Tutorial 01

This document contains an algorithms tutorial with questions about determining the tight Big-O notation for various functions and Python code snippets. It asks the student to find the Big-O of single functions, sums of functions, products of functions, and the time complexity of basic for and while loops in Python code.

Uploaded by

sanjena1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MH1403 Algorithms and Computing

Tutorial 1 Algorithm Analysis


(Week 2, 22.01.2024 – 26.01.2024)

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.2 f (n) = 2100

1.3 f (n) = 2n

1.4 f (n) = 3n

1.5 f (n) = n3

1.6 f (n) = n

1.7 f (n) = n0.01

1.8 f (n) = 4n3/2

1.9 f (n) = 4log(3n)

1.10 f (n) = 6nlog(n)

1.11 f (n) = nlog4 (n)

1.12 f (n) = 2log10 (n)


n
1.13 f (n) = 22

1.14 f (n) = 5n + n2

1.15 f (n) = 2100 + 5n

1.16 f (n) = 10n0.01 + n0.5

1.17 f (n) = 5n + 6log(n)

1.18 f (n) = 5n + 6nlog(n)

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 4. Show that T (n) = a0 + a1 n + a2 n2 + a3 n3 (a3 is a positive


number) is O(n3 ) using the formal definition of the Big-Oh notation.

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

Note that in Python, n**2 means n2 , n**7 means n7 .

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy