Given an integer N, the task is to find the N-th Fibonacci numbers.
Input: N = 3
F(1) = 1, F(2) = 1
F(3) = F(1) + F(2) = 2
Input: N = 6
- The Matrix Exponentiation Method is already discussed before. The Doubling Method can be seen as an improvement to the matrix exponentiation method to find the N-th Fibonacci number although it doesn’t use matrix multiplication itself.
The Fibonacci recursive sequence is given by
F(n+1) = F(n) + F(n-1)
The Matrix Exponentiation method uses the following formula
The method involves costly matrix multiplication and moreover Fn is redundantly computed twice.
On the other hand, Fast Doubling Method is based on two basic formulas:
F(2n) = F(n)[2F(n+1) – F(n)] F(2n + 1) = F(n)2 + F(n+1)2
Here is a short explanation of the above results:
F(n+1) = F(n) + F(n-1) &
F(n) = F(n)
It can be rewritten in the matrix form as:
For doubling, we just plug in “2n” into the formula:
Substituting F(n-1) = F(n+1)- F(n) and after simplification we get,
Below is the implementation of the above approach:
Time Complexity: Repeated squaring reduces time from linear to logarithmic . Hence, with constant time arithmetic, the time complexity is O(log n).
- Find the next fibonacci number
- Find the next Non-Fibonacci number
- Find the previous fibonacci number
- Program to find Nth odd Fibonacci Number
- Program to find last two digits of Nth Fibonacci number
- Find nth Fibonacci number using Golden ratio
- Find Index of given fibonacci number in constant time
- Array range queries to find the maximum Fibonacci number with updates
- Check if sum of Fibonacci elements in an Array is a Fibonacci number or not
- Space efficient iterative method to Fibonacci number
- Check if a M-th fibonacci number divides N-th fibonacci number
- Number of ways to represent a number as sum of k fibonacci numbers
- Find the sum of first N odd Fibonacci numbers
- Finding number of digits in n'th Fibonacci number
- Find two Fibonacci numbers whose sum can be represented as N
- Find the GCD of N Fibonacci Numbers with given Indices
- Nth Even Fibonacci Number
- Nth XOR Fibonacci number
- Find the Nth element of the modified Fibonacci series
- Find length of longest Fibonacci like subsequence
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.