-1

So I know that 1 for loop is O(N) and a for loop nested in a for loop is O(N*N), but what about two for loops not nested?

for example:

def ex(W)
for i in len(range(W)):
    if i == ...:
       return 
for c in len(range(W)):
    if c == ...:
       return
 

would this just be O(N) because each for loop is only running N times?

shuman
  • 7
  • 1

1 Answers1

0

The complexity here would just be O(N + N). However, this is the same as O(N):

O(N + N)
O(2N)
2*O(N)
= O(N)
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360