According to the topic, fibonacci complexity formula is 1.6180339887^N.
Expected complexity is F(20) =1.6180339887^20=15126.99992456369
I have following test:
@Test
public void fibonacciTest() {
AtomicInteger counter = new AtomicInteger();
System.out.println("Fib number=" + fib(20, counter));
System.out.println("Complexity=" + counter.intValue());
}
private int fib(int index, AtomicInteger counter) {
counter.incrementAndGet();
if (index <= 1) {
return index;
}
return fib(index - 1, counter) + fib(index - 2, counter);
}
The output is:
Fib number=6765 Complexity=21891
Question:
Why the output differ from expected complexity?