Is recursion to iteration or vice versa algorithm exists with most efficiency output and tail recursion?
Preferable panguage is C#.
For example: on input this algorithm get next simple function:
public static ulong Factorial(ulong n)
{
return n == 0 ? 1 : n * Factorial(n - 1);
}
And after processing return following:
public static ulong Factorial(ulong n)
{
ulong result = 1;
for (ulong i = 1; i <= n; i++)
result = result * i;
return result;
}