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
,
Look at it like this. Assume the complexity of calculating F(k)
, the kth
Fibonacci number, by recursion is at most 2^k
for k <= n
. This is our induction hypothesis. Then the complexity of calculating F(n + 1)
by recursion is
F(n + 1) = F(n) + F(n - 1)
which has complexity 2^n + 2^(n - 1)
. Note that
2^n + 2^(n - 1) = 2 * 2^n / 2 + 2^n / 2 = 3 * 2^n / 2 <= 2 * 2^n = 2^(n + 1).
We have shown by induction that the claim that calculating F(k)
by recursion is at most 2^k
is correct.