The complexity factor of recursive time is O (n ) calculated through recurrence equations space complexity is also O (n)
In the non- recursive implementation, the space complexity is O ( 1)
Look
int fatorial(int n)
{ int f = 1;
while(n > 0)
{ f = f * n; n = n – 1; }
return f;
I'd classify this as pseudopolynomial time. If you treat the input x as a number, then the runtime is indeed a polynomial in x. However, polynomial time is formally defined such that the runtime of the algorithm must be a polynomial with respect to the number of bits used to specify the input to the problem. Here, the number x can be specified in only Θ(log x) bits, so the runtime of 2log x is technically considered exponential time. Now the case non-recurssive with certainly is exponencial time certainly.
Thanks for your response. I respect your answer. Factorial is dependent on the multiplication. There are some other methods of multiplication just like Schonhage-strassen method gives complexity O(log n( log (log n)). What is your "say" or "opinion"