I am trying to better understand recursion.
As an example, here are two definitions for calculating n! :
def factorial(num, p=1):
if num == 0:
return p
else:
p *= num
return factorial(num-1,p)
and
def factorial(num):
if num == 1:
return num
return num * factorial(num - 1)
Is one better than the other? I understand that the second one builds a call stack, while the first is calculating p at each step and just passing it to another iteration of the function. Are there separate names for these types of functions? Is the first one not recursion?
Just looking for some guidance on understanding the differences here. Thanks!