Z
Z
zlodiak2019-02-16 14:24:53
Python
zlodiak, 2019-02-16 14:24:53

How to calculate the final difficulty?

There is this code:

#!/usr/bin/env python3

a = [10, 20, 30, 40, 50, 60]

for i in range(len(a)):
    print(i, a[i])

LIVE DEMO is here.
Please tell me if I used the correct approach to calculate the final complexity of this code?
len(a) # O(1)
for i in (0, 1, 2, ,3 ,4 ,5) # O(n)
print() # O(1)
total complexity: (O(1) * O( n)) * O(1) = O(n)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Podbolotov, 2019-02-16
@zlodiak

That's right

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question