I have try to understand the Big O Notation worst case runtime. But I still don't quite understand it.
This is some code that I wrote recently:
def g(n):
if n==0:
return 1
elif n==1:
return 2
else:
n_div=n//2
n_mod=n%2
return g(n_div)*g(n_mod)
So I hope that I'm at least right that:
def g(n):
if n==0:
return 1
and:
elif n==1:
return 2
are O(1), so constant.
But what about the else
part.
Is it O(n) because it depends on the n
that I choose?
Can anyone explain what that Big O complexity of the else
part is?