Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write these codes in Matlab IDE and run them to show results. Advanced Computing Assignment-2 (Due 2/11/2020 @11:30 pm) Dynamic Programming is an algorithm design

image text in transcribed
image text in transcribedwrite these codes in Matlab IDE and run them to show results.
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 fis the array you store the sequence. This f shall be defined global and set all elements to -1(fu-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? function y = myfib (n) if (n==1) y= 0; elseif (n==2) y=1; else y = myfib (n-2) +myfib(n-1); end

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions