I was watching: https://www.youtube.com/watch?v=_JtPhF8MshA
Where the following implementation:
int factorial (int n)
{
if (n==0) return 1;
return n * factorial(n-1);
}
with the following:
int factorial (int n)
{
return go(n, );
}
int go(int n, int a)
{
if (n==0) return a;
return go(n-1, a*n);
}
Where he claimed the second is more efficient but my question is why?
Both call the function exactly the same number of times, thus 2 of them are O(n).