Time Complexity analysis of recursion - Fibonacci Sequence
Why Stack Overflow recommends it
Stack Overflow users link it when explaining why recursive Fibonacci runs in exponential time, since it covers both the lower and upper bounds.
Recommended by 2 people across 2 different months, 2015 to 2019.
What it is
A short lesson from the mycodeschool channel that analyzes the time complexity of the naive recursive Fibonacci implementation. It derives both a lower bound (about 2^(n/2)) and an upper bound (2^n) by reasoning about the recursion tree. It is part of a longer recursion series and assumes basic recursion and Big-O knowledge.
What people said
Recommends Nyfiken Gul · 2017-01 · Stack Overflow · on “Prove time complexity of recursive algorithm”
I have been given a recursive algorithm in an assignment, of which I need to prove it has a given Time Complexity. The algorithm is as follows (written in Java) int partDist(String w1, String w2, int w1len, int w2len) { if (w1len == 0) return w2len; if (w2len == 0) return w1len; int res = partDist(w1, w2, w1len - 1, w2len - 1) + (w1.charAt(w1len - 1) == w2.charAt(w2len - 1) ? 0 : 1); int addLetter = partDist(w1, w2, w1len - 1, w2len) + 1; if (addLetter < res) res = addLetter; int deleteLetter = partDist(w1, w2, w1len, w2len - 1) + 1; if (deleteLetter < res) res = deleteLetter; return res; } The assignment is to prove that this algorithm indeed has the time complexity Omega(2^max(n, m)) where
Recommends RBT · 2019-01 · Stack Overflow · on “Computational complexity of Fibonacci Sequence”
A very nice video here [this video] which talks about both lower bound complexity(2^n/2) and upper bound complexity(2^n) of recursive implementation.
Cites Xiaowei Liu · 2015-03 · Stack Overflow · on “Bash Script - Fibonacci”
I do believe that you know "coding FIBONACCI with recursion is NOT a good idea". recursive Fib() -> O(2^n) iterative Fib() -> O(n) Please reference to this youtube video [this video] .