DEV Community

Discussion on: The optimal approach to find the nth Fibonacci number using recursion in Java

Collapse
 
manju4ever profile image
Manjunath Desappa • Edited

Why would you want to take so much pain with recursion. You can do this with O(1) time with the following code. You can apply the same technique for a range or Nth fibonacci.

fib(n) = (Ψ ^n - (1 - Ψ)^n) / sqrt(5), where Ψ = 1.618

Collapse
 
sumant4ssm profile image
Sumant Kumar • Edited

This won't give you correct result after n=70.