I am confused about whether the complexity of the Fibonacci function function is 2^n or the golden ratio raised to power n.
"I have noticed that many websites state that the complexity of this recursion is 2 to the power of n."
I am confused about whether the complexity of the Fibonacci function function is 2^n or the golden ratio raised to power n.
"I have noticed that many websites state that the complexity of this recursion is 2 to the power of n."
Let's take this pseudocode to calculate
Let's call the number of elementary operations (of O(1) complexity) needed to calculate .
Then we have constants and such that:
Here we take addition as a constant time operation, included in .
We can see this sequence:
As = θ(φ), we have that:
= θ(φ+1) = θ(φ)
With Big O we cannot get an equivalent expression by changing the base of an exponentiation. Wikipedia on Big O notation warns about this:
And so we cannot say = θ(2), because φ is not 2, but 1.618...
On the other hand, since in theory big O gives an upper bound, we can actually say that = O(2), but it is not a precise bound. More precise is using big Omega so to identify a tight bound.
In conclusion we have these truths:
But: