result = []
for i in n:
for jj in range(len(m)):
if jj < 3:
result.append((n,m))
else:
jj = len(m)
What is the correct O time complexity for this?
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.
Comments