Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed
image text in transcribedwrite 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

ISBN: B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

e. What are notable achievements of the group?

Answered: 1 week ago