Hello ,
I am trying to make from f_rec (recursive function) to f_iter (iterative function) but I can't.
(My logic was to create a loop to calculate the results of f_rec(n-1), another loop for 2*f_rec(n-2) and one loop for f_rec(n-3);
But I'm wrong)
1 2 3 4 5 6 7 8 9 10 11
int f_rec(int n)
{
if(n>=3)
return f_rec(n-1)+2*f_rec(n-2)+f_rec(n-3);
elsereturn 1;
}
int f_iter(int n)
{
}
I also think that my run time for the f_rec is 3^n , please correct me if I'm wrong.