def foo(n):
def bar(n):
if n == 0:
return 0
else:
return 1 + bar (n - 1)
return n * bar(n)
How can I calculate what is the time complexity for the running time of foo in terms of its input n? What about space complexity?
Let's break it down:
This appears linear in time and memory -
O(n)
.