What is the Time Complexity of this code sample? like nested loop, but inner loop is a fixed number

tim
result = []
for i in n:
  for jj in range(len(m)):
    if jj < 3:
      result.append((n,m))
    else:
      jj = len(m)
  • m, n are two python array
  • inner loop is maximum 3

Thinking

  • O(n)? because inner looping is in a fixed amount
  • O(n*m)?
  • O(n*3)? this is not the correct way :(

What is the correct O time complexity for this?

OmG

Time complexity of the statement inside the inner loop is in O(1). Because, it is just only one comparison and one variable assignment, and computing the len(m) is done in O(1). The remaining is straightforward: two nested loop with n and m iterations. Therefore, the time complexity is O(m * n).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

What is the time complexity of this for loop nested in a while loop?

Time Complexity Nested Loop Inner Loop + Outer Loop

Time complexity of the inner loop

What is the time complexity of this nested loop where the inner loop grows by a factor of the outer?

Time complexity of nested for loops where inner loop depends on outer loop

What is the time complexity of the following nested loop dependency?

What will be the time complexity of a for loop nested 2 times?

What is the time-complexity of this nested for loop?

what is the Time Complexity of a nested loop in a recursive function?

What is the time complexity for a nested loop in this case?

What is the time complexity of this function? (nested for loop)

Time complexity nested loop

Time complexity of nested for loop

Time complexity for a nested for loop

Time Complexity - nested for loop

Time complexity on nested for loop

What is the time complexity of this loop?

What is the time complexity for this loop

Time complexity of an unorthodox nested for loop

reduce the time complexity of nested for loop

Average Time Complexity of Nested Loop

Time complexity of a triple nested for loop

Time complexity of nested while loop

What is Big O notation (Time Complexity) of non nested for and while loop?

Time complexity of nested loop dependent on the outer loop

Time complexity with for loop nested in while loop

What is the run time complexity of this for loop?

What is the time complexity of this while loop?

Time complexity for inner loop from 0 to i