Problem : How to speed up a recursion method using other techniques.
Simple Fibonacci sequence method uses recursion to output the Nth number of the input.
Any suggestions would be great, thank you.
ex; putting in 50 would take nearly a minute to finally get an output.
Edit: Change of problem text, as it wasn't recursion being too slow, it was my code.
public static long cycle(int x) {
if(x<=1) {
return x;
} else {
return cycle(x-1)+cycle(x-2);
}
}
Aucun commentaire:
Enregistrer un commentaire