G-Fact 18 | Finding nth Fibonacci Number using Golden Ratio

1.3

We have discussed different methods to find nth Fibonacci Number.

Following is another mathematically correct way to find the same.

nth Fibonacci Number Fn = fib1.

Here φ is golden ratio with value as fib2.

The above formula seems to be good for finding nth Fibonacci Number in O(Logn) time as integer power of a number can be calculated in O(Logn) time. But this solution doesn’t work practically because φ is stored as a floating point number and when we calculate powers of φ, important bits may be lost in the process and we may get incorrect answer.

References:
https://www.youtube.com/watch?v=-EQTVuAhSFY
http://en.wikipedia.org/wiki/Fibonacci_number

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

GATE CS Corner    Company Wise Coding Practice

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.

Recommended Posts:



1.3 Average Difficulty : 1.3/5.0
Based on 8 vote(s)










Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.