I made this code.. And I need to get the best of it.. I really need the best performance of calculating fibonacci numbers.. please help be..
I've read some code of this type of calculation and I think I got the best of them..
Avaliate this for me.. plz..
ps: And I really need the BigInteger.. I'll calculate Fibonacci of enormous numbers
ps2: I have calculated some big numbers with this algorithm and I got a great response time.. but I need to know whether it could be better
ps3: to run this code you'll need to use this VM argument -Xss16384k
(StackSize)
public class Fibonacci {
private static BigInteger[] fibTmp = { BigInteger.valueOf(0), BigInteger.valueOf(1) };
public static BigInteger fibonacci(long v) {
BigInteger fib = BigInteger.valueOf(0);
if (v == 1) {
fib = BigInteger.valueOf(1);
} else if (v == 0) {
fib = BigInteger.valueOf(0);
} else {
BigInteger v1 = fibonacci(v - 1);
BigInteger v2 = fibTmp[(int) (v - 2)];
fib = v1.add(v2);
}
synchronized (fibTmp) {
if (fibTmp.length - 1 < v)
fibTmp = Arrays.copyOf(fibTmp, (int) (v + 10));
fibTmp[(int) v] = fib;
}
return fib;
}
}