The terms in the Fibonacci sequence are given by:
F1 = 1, F2 = 1; Fn = Fn-1 + Fn-2
Consider the following recursive algorithm to calculate the nth Fibonacci number:
return Fib(n-1) + Fib(n-2);
What is the running time of the recursive Fib? What is the running time of an efficient DP algorithm to calculate the nth Fibonacci number?
Both algorithms are O(n)
Recursive: O(n^2) and DP: O(n)
Recursive: Theta(2^n) and DP: Theta(n^2)
Recursive: O(2^n) and DP: Theta(n)
Recursive: O(4^n) and DP: O(1)