`
def func5(n, m):
i = 0
while i < n:
j = 1
while j < m:
print(i+j)
j *= 3
i += 1
`
I have gotten answers O(n*m) and O(n(log(m)). Which is it?
`
def func5(n, m):
i = 0
while i < n:
j = 1
while j < m:
print(i+j)
j *= 3
i += 1
`
I have gotten answers O(n*m) and O(n(log(m)). Which is it?
Copyright © 2021 Jogjafile Inc.
for each iteration of outer loop,
lets assume that inner loop runs for 'k' times which implies the values of 'j' are
after this for next iteration of inner loop the value of 'j' will be greater than or equal to m. so, the loop stops
which implies that inner loop runs for log(m) times
In general, Big-Oh implies upper bound.