The Fibonacci numbers are the numbers in the following integer sequence 0, 1, 1, 2, 3, 5, 8, 13…
Mathematically Fibonacci numbers can be written by the following recursive formula.
For seed values F(0) = 0 and F(1) = 1 F(n) = F(n-1) + F(n-2)
Before proceeding with this article make sure you are familiar with the recursive approach discussed in Program for Fibonacci numbers
Analysis of the recursive Fibonacci program:
We know that the recursive equation for Fibonacci is =++.
What this means is, the time taken to calculate fib(n) is equal to the sum of time taken to calculate fib(n-1) and fib(n-2). This also includes the constant time to perform the previous addition.
On solving the above recursive equation we get the upper bound of Fibonacci as but this is not the tight upper bound. The fact that Fibonacci can be mathematically represented as a linear recursive function can be used to find the tight upper bound.
Now Fibonacci is defined as
The characteristic equation for this function will be
– – =
Solving this by quadratic formula we can get the roots as
= (+)/ and =( – )/
Now we know that solution of a linear recursive function is given as
where and are the roots of the characteristic equation.
So for our Fibonacci function = + the solution will be
Clearly and are asymptotically the same as both functions are representing the same thing.
Hence it can be said that
or we can write below (using the property of Big O notation that we can drop lower order terms)
This is the tight upper bound of fibonacci.\
1.6180 is also called the golden ratio. You can read more about golden ratio here: Golden Ratio in Maths
This article is contributed by Vineet Joshi. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- A Time Complexity Question
- Time Complexity of Loop with Powers
- An interesting time complexity question
- Time Complexity of building a heap
- Understanding Time Complexity with Simple Examples
- Practice Questions on Time Complexity Analysis
- Time Complexity where loop variable is incremented by 1, 2, 3, 4 ..
- Time Complexity Analysis | Tower Of Hanoi (Recursion)
- Python Code for time Complexity plot of Heap Sort
- Find Index of given fibonacci number in constant time
- Count Fibonacci numbers in given range in O(Log n) time and O(1) space
- Time Complexity of a Loop when Loop variable “Expands or Shrinks” exponentially
- C Program for Fibonacci numbers
- Program for Fibonacci numbers
- Python Program for n-th Fibonacci number