Could you please explain the complexity of the following algorithm?
public BigInteger fibBigInt() {
return fibBigInt(
BigInteger.valueOf(n),
ONE,
BigInteger.valueOf(0));
}
private BigInteger fibBigInt(BigInteger start, BigInteger val, BigInteger previous) {
if (start.compareTo(BigInteger.valueOf(0)) == 0) {
return previous;
}
return fibBigInt(
start.subtract(ONE),
val.add(previous),
val);
}
How does this recursion run in O(n) time? I'm a bit confused.