The purpose of this assignment is to reinforce dynamic programming algorithms. Specifically, the assignment is to do problem 15-8 on page 409 of the text. In addition, implement the algorithm that you construct. You may write your program in any modern language. I suggest Python because the output can be put in a visual representation
Part 1 reinforces the recurrence relation of the Fibonacci sequence with a comparison to the dynamic programming algorithm. (goals 1, 3, 4)
Using the same algorithm in different ways illustrates the efficiency achieved by different algorithmic methods.
Part 2 reinforce the use of algorithms using a modern language.
DP algo->
FIB(n)
dp=[0,1]
for i=2 to n do -> add(dp[i-1]+dp[i-2]) to dp list
return dp list
Code in Python
1) recursion
2) recursion with memoization
3) dynamic programming
Code
def fibrec(n):
if n<=1: return n
else: return fibrec(n-1)+fibrec(n-2)
for i in range(10):
print(fibrec(i),end=' ')
def fibrecDP(n, dp):
if n<=1:
dp[n]=n
return n
if dp[n]==-1: dp[n] = fibrecDP(n-1,dp)+fibrecDP(n-2,dp)
return dp[n]
dp=[]
n=10
for i in range(n+1):
dp.append(-1)
fibrecDP(n,dp)
print(dp)
def fibDP(n):
dp = [0,1]
for i in range(2,n+1):
dp.append(dp[i-1]+dp[i-2])
return dp
n=10
print(fibDP(n))
The purpose of this assignment is to reinforce dynamic programming algorithms. Specifically, the assignment is to...
Overview The purpose of this assignment is to practice functional programming in the Racket Programming Language and to also reinforce the notion of the list as a universal data structure, by implementing various operations on binary search trees. Specification A binary search tree is a binary tree which satisfies the following invariant property: for any node X, every node in X's left subtree has a value smaller than that of X, and every node in X's right subtree has a...
Objective In this assignment, you will practice solving a problem using object-oriented programming and specifically, you will use the concept of object aggregation (i.e., has-a relationship between objects). You will implement a Java application, called MovieApplication that could be used in the movie industry. You are asked to implement three classes: Movie, Distributor, and MovieDriver. Each of these classes is described below. Problem Description The Movie class represents a movie and has the following attributes: name (of type String), directorName...
Advanced Object-Oriented Programming using Java Assignment 4: Exception Handling and Testing in Java Introduction - This assignment is meant to introduce you to design and implementation of exceptions in an object-oriented language. It will also give you experience in testing an object-oriented support class. You will be designing and implementing a version of the game Nim. Specifically, you will design and implement a NimGame support class that stores all actual information about the state of the game, and detects and throws...
This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...