Are there algorithms that are only feasible in a recursive manner? If yes, how can one identify these algorithms?
Consider the following as a case study.
In order to approximate a exponential, one can use.
ef ≈
1 + f(1 + f/2(1 + f/3(1 + f/4)))
Here is a function that computes this approximation at a level of n steps using recursion.
exp_approximation = function(f, n, i = 2)
{
if (n == 1)
{
return( 1 + f/i )
} else
{
1 + f/i * exp_approximation(f,n=n-1,i=i+1)
}
}
Is it possible to write the same algorithm using iteration instead of recursion?
I wrote my code in R but I welcome solution in pseudo code other some other commonly used language such as C, C++, Java, Python, ...