I have a simple recursive algorithm, which returns Fibonacci numbers:
private static double fib_recursive(int n){
if(n <= 2) return 1;
else return fib_recursive(n-1) + fib_recursive(n-2);
}
Now my task is to return the time, which this method would take to calculate the 400-th fibonacci number on a given computer e.g. fib_recursive(400). “Would” is in bold, because I can’t run the function, as it would take to long for this method to give an answer.
How can it be best achieved?
Calculate how much time to do each recursive call, figure out how many recursive calls, and you have an answer.
There are faster ways to do this, using a smarter recursion algorithm, but for your algorithm just put in some timing information.