Question: write the code for this assignment in Matlab. Advanced Computing Assignment-2 (Due 2/11/2020 @11:30 pm) Dynamic Programming is an algorithm design technique for optimization problems.
write the code for this assignment in Matlab. Advanced Computing Assignment-2 (Due 2/11/2020 @11:30 pm) Dynamic Programming is an algorithm design technique for optimization problems. Similar to the divide-and-conquer method, dynamic programming solves problems by combining the solutions to sub-problems. Question: You have given a simple recursive Fibonacci code (see the attachment in the Elearn, myfib.m) Write your own dynamic programming version of recursive Fibonacci code using the pseudo code given below: myfib2(n) 1. if n = 0 return f [1] =0 2. if n = 1 return f [2] =1 3. If f(n-2] == -1 4. f[n-2] =myfib2(n-2) 5. If f(n-1) == -1 6. f[n-1] =myfib2(n-1) //Use saved results & store the nth term in table. 7. f[n] = f(n-1) + f[n-2] 8. return f[n] Keep in mind that f is the array you store the sequence. This f shall be defined global and set all elements to -1(f=-1*ones (1, n)) Compare simple recursive Fibonacci program with the one you write the dynamic version of it using various sizes of n (ex 15, 20,30, 40). You shall use embedded MATLAB function tic, toc to determine the time it takes for both algorithms. Discuss the time complexity of each method and compare them. Which one works faster and what is the time complexity of it? ocuments 1 MATLAB Editor-CAUserslampembel Downloads\myfib.m myfib. mx + function y = myfib (n) if (n==1) y= 0; elseif (n==2) y=1; else y = myfib (n-2) +myfib(n-1); 1 1 1 COWN 1 1 1 Command Window New to MATLAB? See resources for Getting Started >> myfib (5) ans - x >>
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
