1
I’m studying recursion, and I wanted to find a way to make a recursive algorithm for efficient Fibonacci sequence, where the algorithm is not exponential. How will I save the value of subproblems?? I was thinking of using the vector and try to save the subproblems or whatever
unsigned long long fibonacci (unsigned long long n){
int cont = n, unsigned long long fib[cont];
if(n < 2)
return n;
else if(n == cont)
return fib[cont];
else
fib[cont] = return fibonacci(n-1) + fibonacci(n-2);
}
Recursiveness to get efficiency seems a bit incoherent to me. If you need efficiency, why not use a simple repetition loop?
– Woss
is because the exercise asks to be solved with recursion
– user66436