Question: Consider the algorithm for the Fibonacci sequence. a) Write a recursive algorithm which computes F(n) for and show that its running-time complexity is exponential with
Consider the algorithm for the Fibonacci sequence.
a) Write a recursive algorithm which computes F(n) for
and show that its running-time complexity is exponential with n. Hint: the Fibonacci number can be approximated as
where
is the golden ratio (=
= 1.61801.. ) and [.] denotes rounding to the nearest integer.
b) Add memoization to the recursive algorithm and show that the running-time is 0(n)..
c) Reimplement the memoized recursive algorithm as a bottom-up iterative algorithm. (Note an optimality substructure is not in this exercise.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
