Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ECS 32B – Introduction to Data Structures

Homework 01

Submit only one pdf filevia Gradescope. Do not submit a separate file for each problem. If you handwrite your solutions, make sure they are clear and readable.

Problem 1 (10 points each)

For each of the following functions, do the following:

. Calculate T(n), making sure not to discard constants or low-order terms yet (you may or may not count the counting variable in a for loop)

. Given what you think is the Big-O performance for the function

. Prove that your proposed Big-O for the function is correct (make sure to show your work; do not just provide values for c and n0)

(1) def fun1 ( n ) :

x  =  0

for i in range ( 2 ,  n / 2 ) :

x  =  x  *  2

return x

(2) def fun2 ( n ) :

x  =  0

for i in range ( n ) :

for j in range ( n ) :

for k in range ( 1 ,  n ) :

x  =  x  +  1

return x

(3) def fun3 ( n ) :

x  =  0

i   =  2  *  n

while i  >=   1 :

x  =  x  —  i

i   =   i  —  1

return x

(4) def fun4 ( n ) :

x  =  n

for i in range ( n  *  n ) :

x  =  x  +  2

return x

(5)                             #   l s t    i s   a   li s t    of   i n t eg e r s

def fun5 ( l s t ) :

x  =  0

for y in l s t :

x  =  x  +  y

return x

Problem 2 (10 points each)

Suppose an algorithm solves a problem of input size n in at most the number of steps listed for each T(n) given below. Calculate the Big-Θ (not just Big-O) for each T(n). Show your work, including values for c and n0 .

(1)  T(n) = 10

(2)  T(n) = 2n3 + 1

(3)  T(n) = n4 + 2n2 + nlogn

(4)  T(n) = log(5 x 2n )

(5)  T(n) = 3n2logn