0% found this document useful (0 votes)
17 views3 pages

Homework Week 2 Big Oh

This document contains a homework assignment on data structures and algorithms from the Faculty of Mathematical Economics. The homework has four problems: 1) Analyzing time complexity using Big O notation, 2) Calculating time complexity for several algorithms, 3) Implementing binary search on sample lists, and 4) Guidelines for submitting the homework in Jupyter notebook format by the due date.

Uploaded by

Thành Lộc
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)
17 views3 pages

Homework Week 2 Big Oh

This document contains a homework assignment on data structures and algorithms from the Faculty of Mathematical Economics. The homework has four problems: 1) Analyzing time complexity using Big O notation, 2) Calculating time complexity for several algorithms, 3) Implementing binary search on sample lists, and 4) Guidelines for submitting the homework in Jupyter notebook format by the due date.

Uploaded by

Thành Lộc
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

Faculty of Mathematical Economics

Data Structures and Algorithms

Instructor: Nguyen Thanh Tuan


DSEB Class of 2021 - 2024

Homework Assignment Week 1


Topic: Big O Notation
Date Created: December 22, 2022

Problem 1: Algorithm Analysis Fundamentals


Give the appropriate answers for the questions below:

1. How do you use Big O notation to analyze the time complexity of an algorithm?
Why is Big O analysis important?

2. What a worst-case scenario is in the context of Big O Analysis? Is it necessary to


calculate exact runtimes when analyzing algorithms with Big O notation? Why or
why not?

3. (Optional) What is your understanding of space complexity? Is it different from


time complexity? If yes, then how? When would you choose a solution with a better
space complexity over one with a better time complexity?

Problem 2: Time Complexity


Find the time complexity for the following algorithms:

1. Algorithm 1:
1 def deductOne ( num ) :
2 num -= 1
3 return num

2. Algorithm 2:
1 def s ( _list ) :
2 prefix_sum = 0
3 for i in _list :
4 prefix_sum + = 1
5 return prefix_sum

3. Algorithm 3:
Data Structures and Algorithms Homework Week 1

1 testList = [1 , 3 , 4 , 5 , 61 , 96 , 69 , 13 , 22 , 2001]
2
3 def al ( testList ) :
4 for i in range ( len ( testList ) ) :
5 for j in range ( i +1 , len ( testList ) ) :
6 if testList [ j ] < testList [ i ]:
7 testList [ j ] , testList [ i ] = testList [ i ] , testList [ j ]
8 return testList

4. Algorithm 4:
1 a = 100
2 N = 40
3
4 def add (a , N ) :
5 for i in range ( N ) :
6 a = a + 10
7 return a

5. Algorithm 5:
1 def count (A , B ) :
2 n = len ( A )
3 count = 0
4 for i in range ( n ) :
5 total = 0
6 for j in range ( n ) :
7 for k in range (1+ j ) :
8 total += A [ k ]
9 if B [ i ] == total :
10 count += 1
11 return count

6. Algorithm 6:
1 def fibo ( n ) :
2 if n <= 1:
3 return n
4 return fibo (n -1) + fibo (n -2)

Problem 3: Binary Search


Implement Binary Search to find value a pre-defined in the following lists, and print the
iteration time with each search. Print "Not Found" if there is no value a in the list
1. List 1:
1 a = 5
2 list = [1 ,2 ,4 ,6 ,7 ,9]

2. List 2:
1 a = "f"
2 list = [ 'a ' , 'b ' , 'c ' , 'd ' , 'e ' , 'f ' , 'g ' , 'h ' , 'i ' , 'j ' , 'k ' , 'l ' ,
'm ' , 'n ' , 'o ' , 'p ' , 'q ' , 'r ' , 's ' , 't ' , 'u ' , 'v ' , 'w ' , 'x ' , 'y '
, 'z ']

2
Data Structures and Algorithms Homework Week 1

3. List 3:
1 a = 5
2 list =[2 , 1 , 2163 , -125 , 1 , 5 , 7 , 9 , 6 , 5 , 3 , 11 , 22 , 55 , 88 , 99 ,
111 , 222 , 555 , 321 , 653 , 963 , 654 , 998 , 651]

4. List 4:
1 a = " foo "
2 list = [ ' aac ' , ' bac ' , ' cbaasc ' , ' duc ' , ' enk ' , ' fire ' , ' foo ' , ' hv ' ,
' isg ' , ' loj ' , ' qwek ' , ' scsl ' , ' vfbgm ' , ' nig ' , ' go ' , ' prii ' , '
qqqq ' , ' kkree ' , ' lis ' , ' acst ' , ' qweu ' , ' vfsdv ' , ' wfefe ' , ' xsfed '
, ' yagr ' , ' zyz ']

Guidelines for submission

• Your submission must be under the .ipynb format.

• Your submission will be graded and it is likely that homework grade will contribute
as a component in your GPA.

• If your submission is later than the due date without special consideration approval,
you will receive a penalty on your mark.

You might also like