Question 11. [5 MARKS]
Each code fragment in the table below operates on list L, which has length k where k is very large - at
least in the tens of thousands. For each fragment, give an expression in terms of k for how many times
happy! is printed, and circle whether the behaviour is constant, linear, quadratic or something else.
Code
How many times is happy! printed?
Complexity
(circle one)
for i in range (len (L)):
print('happy!')
for item in L:
print('happy!')
constant
linear
quadratic
something else
for i in range (len(L))
for item in L[:i]:
print('happy!'
constant
linear
quadratic
something else
# Precondition: len(L) % 10 == 0
i = 0
while i < len(L):
print("happy!')
i = i + len(L) // 10
constant
linear
quadratic
something else
for item in L[1000:2000] :
print('happy!'
constant
linear
quadratic
something else
for item in L[10:] :
print('happy!'
constant
linear
quadratic
something else