The complexity of a naive recursive fibonacci is indeed 2โฟ.

T(n) = T(n-1) + T(n-2) = T(n-2) + T(n-3) + T(n-3) + T(n-4) = 
= T(n-3) + T(n-4) + T(n-4) + T(n-5) + T(n-4) + T(n-5) + T(n-5) + T(n-6) = ...

In each step you call T twice, thus will provide eventual asymptotic barrier of:
T(n) = 2โ‹…2โ‹…...โ‹…2 = 2โฟ

bonus: The best theoretical implementation to fibonacci is actually a close formula, using the golden ratio:

Fib(n) = (ฯ†โฟ โ€“ (โ€“ฯ†)โปโฟ)/sqrt(5) [where ฯ† is the golden ratio]

(However, it suffers from precision errors in real life due to floating point arithmetics, which are not exact)

Answer from amit on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ time-complexity-recursive-fibonacci-program
Time complexity of recursive Fibonacci program - GeeksforGeeks
October 20, 2017 - We know that the recursive equation for Fibonacci is = T(n-1) + T(n-2) + O(1). 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 ...
๐ŸŒ
Reddit
reddit.com โ€บ r/algorithms โ€บ complexity of recursive fibonacci sequence with caching
r/algorithms on Reddit: complexity of recursive fibonacci sequence with caching
June 29, 2021 -

So, of course, the typical version of the recursive fibonacci suquence looks like:

function fib(n):

    if n < 2:

        return n

    return fib(n - 1) + fib(n - 2);

And its complexity is O( 2n )

Now, in this instance Cache[] is an array with n elements. Since the base cases are known, we can say Cache[0] = 0 and Cache[1] = 1. The rest of the Cache array is set equal to some placeholder value, say -1 in this instance, so we get:

Cache[0,1,2,...,n] = [0,1,-1,...,-1]

function fib(n):

    if n < 2:

        return n

    n_1 = Cache[n - 1]

    if n_1 == -1:
        
        n_1 = fib(n - 1, Cache)

        Cache[n - 1] = n_1

    n_2 = Cache[n - 2]

     return n_1 + n_2

Now, I get to thinking, the complexity of this would be O(n) because the base case is O(1), the only branch that is ever calculated is the initial n - 1 branch, and by that time ever n - 2 branch has already been calculated, going back to the base case. Is my thinking correct here?

This isn't homework or anything. Just a thought experiment.

Discussions

algorithm - Why is the complexity of computing the Fibonacci series 2^n and not n^2? - Stack Overflow
I am trying to find complexity of Fibonacci series using a recursion tree and concluded height of tree = O(n) worst case, cost of each level = cn, hence complexity = n*n=n^2 ... It is theta (F_N) (and so O(2^N)), even if you consider the complexity of adding two n bits numbers to be Polynomial in N, I believe. ... As a followup question, is the time ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
What is the expression for time complexity for finding Fibonacci number using recursion? a. T ( n ) = T ( n - 1 ) + O ( n ) b. T ( n ) = T ( n - 1 ) + T ( n / 2 ) c. T ( n ) = 2 ^ { * } T ( n / 2 ) + O ( 1 ) d. T ( n ) = T ( n - 1 ) + T ( n - 2 )
Solution For What is the expression for time complexity for finding Fibonacci number using recursion? a. T ( n ) = T ( n - 1 ) + O ( n ) b. T ( n ) = More on askfilo.com
๐ŸŒ askfilo.com
1
February 18, 2025
Can Fibonacci numbers be calculated using recursion in O(N) without memo?
Surprised I don't see this mentioned, but there is a nifty way to do it without memoization -- in O(log N). Matrix Exponentiation. Basically, consider your processing step: you have two values, the previous and current numbers. You do a nice clean simple linear transformation, and end up with the current and next. Flip it around a bit: you have an incoming 2-vector, you do a matrix multiply, giving a new 2-vector. Doing it several times to get new numbers just stacks up a sequence of matrix multiplies, which you can re-associate to be a matrix to the Nth power times the starting vector. More thinking. If I wanted a matrix to the 8th power, I'd not multiply it eight times. I'd square it, then square that, then square that. So O(log N) matrix multiplies (this is called Russian Peasant Exponentiation, or The Egyptian Method). Up to some N, the O(N) method using fast steps will be faster than the O(log N) method which does Matrix Multiplies, but at some N, the O(log N) will pull ahead. OK, trying some Bad Text Graphics ... One FIB step, as matrix multiply: โŽก Fโ‚‚ โŽค โŽก 0 1 โŽค โŽก Fโ‚ โŽค โŽข โŽฅ := โŽข โŽฅ ร— โŽข โŽฅ โŽฃ Fโ‚ƒ โŽฆ โŽฃ 1 1 โŽฆ โŽฃ Fโ‚‚ โŽฆ Eight FIB steps: โŽก Fโ‚ˆ โŽค โŽก 0 1 โŽคโธ โŽก Fโ‚ โŽค โŽข โŽฅ := โŽข โŽฅ ร— โŽข โŽฅ โŽฃ Fโ‚‰ โŽฆ โŽฃ 1 1 โŽฆ โŽฃ Fโ‚‚ โŽฆ So for N steps, compute the Nth power of that matrix, which can be done in O(log N). You can see a bunch of different "takes" on this method here: https://rosettacode.org/wiki/Fibonacci_matrix-exponentiation [Edit to add: looking for even faster ways to do the matrix exponentiation will lead you to looking at very cool stuff that totally does not apply to this problem. You know, just in case you are math-curious ;] More on reddit.com
๐ŸŒ r/compsci
19
11
July 3, 2024
Time Complexity of Recursive Functions
Merge sort is a true divide-and-conquer algorithm: the two recursive calls are each responsible for half of the list. A naive recursive Fibonacci implementation would be more accurately described as "duplicate-and-conquer". When calculating fib(n) and fib(n+1) for an addition, the latter call duplicates all the work of the former call. But you can have a linear recursive Fibonacci implementation by passing additional parameters: fib'(0,x,y) = x fib'(1+n,x,y) = fib'(n, x+y, x) fib(n) = fib'(n,1,0) Think of it as a dynamic programming solution filling in an array of Fibonacci numbers, but keeping only the bits of the array you need for the next step. More on reddit.com
๐ŸŒ r/algorithms
11
2
June 4, 2024
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ algorithms โ€บ computational complexity of fibonacci sequence
Computational Complexity of Fibonacci Sequence | Baeldung on Computer Science
March 18, 2024 - First, we implemented a recursive algorithm and discovered that its time complexity grew exponentially in n. Next, we took an iterative approach that achieved a much better time complexity of O(n).
๐ŸŒ
Evoniuk
evoniuk.github.io โ€บ posts โ€บ fibonacci.html
Time Complexity of Recursive Fibonacci
int fibonacci(int n) { if (n == 1 || n == 2) return 1; return fibonacci(n - 1) + fibonacci(n - 2); } It's simple enough, but the runtime complexity isn't entirely obvious. An initial assumption might be that it is O(2n), as it is a recursive formula that branches twice each call, but this isn't ...
๐ŸŒ
YouTube
youtube.com โ€บ watch
Big O Notation Series #7: Time Complexity Visualization of Recursive Fibonacci - YouTube
In this video, I will show you how to visualize and understand the time complexity of recursive fibonacci. You will learn about Big O(2^n)/ exponential growt...
Published: February 27, 2021
Find elsewhere
๐ŸŒ
Medium
syedtousifahmed.medium.com โ€บ fibonacci-iterative-vs-recursive-5182d7783055
Fibonacci Iterative vs. Recursive | by Ryan Syed | Medium
February 21, 2021 - Hence the time taken by recursive Fibonacci is O(2^n) or exponential. For the iterative approach, the amount of space required is the same for fib(6) and fib(100), i.e. as N changes the space/memory used remains the same.
๐ŸŒ
Medium
medium.com โ€บ @yingpeng0221 โ€บ analysis-of-time-and-space-complexity-in-recursive-algorithms-5a82ea278046
Analysis of Time and Space Complexity in Recursive Algorithms | by Ying Peng | Medium
September 22, 2023 - def fibonacci_recursive(n): if n <= 0: return 0 elif n == 1: return 1 else: return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2) ... For recursive algorithms, the code is typically concise, and from an algorithmic standpoint, they ...
๐ŸŒ
AlgoDaily
algodaily.com โ€บ lessons โ€บ fibonacci-sequence-using-dynamic-programming-379b70c0
AlgoDaily - Fibonacci Sequence using Dynamic Programming
It's important to note that the recursive solution for the Fibonacci sequence is not efficient for larger values of n. The recursive approach has overlapping subproblems and performs redundant calculations, which can lead to exponential time complexity.
๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ home โ€บ technologies โ€บ c# โ€บ fibonacci series : recursion, memoization, and optimal approach
Fibonacci Series : Recursion, Memoization, and Optimal ...
October 1, 2024 - So, in this approach, we have reduced the time complexity to O(n) from O(2^n) Space Complexity: O(n) โ€“ We need additional space to store the results of the Fibonacci calculations in the dictionary, plus the recursion depth, which means space complexity is still the same as the previous approach.
๐ŸŒ
AlgoCademy
algocademy.com โ€บ link
Fibonacci Number in O(n) Time and O(1) Space using Java
The Fibonacci sequence is widely used in computer science and mathematics, often appearing in problems related to dynamic programming, recursion, and algorithm optimization. Potential pitfalls include inefficient recursive solutions that have exponential time complexity and excessive space ...
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Fibonacci_sequence
Fibonacci sequence - Wikipedia
2 weeks ago - These last two identities provide a way to compute Fibonacci numbers recursively in O(log n) arithmetic operations. This matches the time for computing the n-th Fibonacci number from the closed-form matrix formula, but with fewer redundant steps if one avoids recomputing an already computed ...
๐ŸŒ
Academia.edu
academia.edu โ€บ 48058949 โ€บ Review_A_State_of_the_Art_of_Time_Complexity_Non_Recursive_and_Recursive_Fibonacci_Algorithm_
(PDF) Review: A State-of-the-Art of Time Complexity (Non-Recursive and Recursive Fibonacci Algorithm)
May 4, 2021 - Binet's formula provides a non-recursive way to compute Fibonacci numbers efficiently, directly yielding values for large n. This contrasts with recursive methods that show exponential growth in time complexity.
๐ŸŒ
Filo
askfilo.com โ€บ cbse โ€บ smart solutions โ€บ what is the expression for time complexity for finding fibonac
What is the expression for time complexity for finding Fibonacci number u..
February 18, 2025 - Identify the recursive definition of Fibonacci: F(n) = F(n-1) + F(n-2). Recognize that to compute F(n), we need to compute both F(n-1) and F(n-2). Express the time complexity as T(n) = T(n-1) + T(n-2).
๐ŸŒ
W3Schools
w3schools.com โ€บ dsa โ€บ dsa_algo_simple.php
DSA Simple Algorithm
To be more precise, the number of function calls will double every time we increase the Fibonacci number we want by one. Just take a look at the number of function calls for \(F(5)\): To better understand the code, here is how the recursive function calls return values so that \(F(5)\) returns the correct value in the end:
๐ŸŒ
AlgoCademy
algocademy.com โ€บ link
Recursive Fibonacci in Python with Time Complexity Analysis
The naive approach directly translates the mathematical definition of the Fibonacci sequence into a recursive function. However, this approach is not optimal due to its exponential time complexity.
๐ŸŒ
Homework.Study.com
homework.study.com โ€บ explanation โ€บ analyze-the-recursive-version-of-the-fibonacci-series-define-the-problem-write-the-algorithm-and-give-the-complexity-analysis.html
Analyze the recursive version of the Fibonacci series. Define the problem, write the algorithm and give the complexity analysis. | Homework.Study.com
Consider the following recursive algorithm, where n is the input, n geq 1: Algorithm T(n) # if n = 1 return 1; # else return T(n-1) + 2 * n - 1; a. Set up the recurrence equation and initial condi ยท Give an algorithm for the following problem and determine its time complexity.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-write-a-java-program-to-find-the-fibonacci-series
How to Write a Java Program to Get the Fibonacci Series
June 28, 2022 - The time complexity for this approach is O(N), which is linear time complexity as we traversed through the array only once. The space complexity for this approach is O(N), which is linear space complexity as we stored answers to sub-problems ...