Professional Documents
Culture Documents
Consultatii 9.01 - Complexitati PDF
Consultatii 9.01 - Complexitati PDF
2. Let n be the size of the list L passed to this function. Which of the following most
accurately describes how the runtime of this function grows as n grows?
def f2(L):
sum = 0
i = 1
while i < len(L):
sum = sum + L[i]
i = i * 2
return sum
3. def f1(n):
for i in range(1, n):
print(i)
print(3 + i)
4. def f2(n):
while n - 5 > 0:
print(n * 2 + 4)
n = n - 1
for i in range(1, 7):
print(i)
5. def f3(n):
for i in range(n):
for j in range(i):
print(i + j)
7. def f5(n):
count = 0;
for i in range(math.sqrt(n)):
count += 1
for j in range(math.sqrt(n) / 4):
count += 1
for k in range(8 + j):
count += 1
8. def f6(n):
sum = 0;
for i in range(math.sqrt(n) / 2):
for j in range(i, 5 + i):
sum += 1
9. def f7(n):
sum = 0;
for i in range(math.sqrt(n) / 2):
for j in range(i, 5 + i):
for k in range(j, 3 + j):
sum += 1
if n <= 0:
return 1;
else:
return 1 + recursiveFun5(n - 5)
for i in range(n):
for j in range(i, i * i):
if j % i == 0:
for k in range(j * j):
print('*')