Question

In: Computer Science

Choose a problem that lends to an implementation that uses dynamic programming. Clearly state the problem...

Choose a problem that lends to an implementation that uses dynamic programming. Clearly state the problem and then provide high-level pseudocode for the algorithm. Explain why this algorithm can benefit from dynamic programming.

Solutions

Expert Solution

Problem Statement

Calculate the nth term of Fibonacci number.The fibonacci numbers are in the following sequence.

0,1,1,2,3,5,8,13,21,34...

Pseudocode(without dynamic programming)

1. int fib(n){ //function that calculates nth fibonacci number

2. if(n <= 1)

3. return n;

4. else{

5. return fib(n - 1) + fib(n - 2);

6.}

7.}

Pseudocode(dynamic programming)

1.int fib(n); //declaring array dp where fib(i) represents ith fibonacci number.

2.fib(0) = 0,fib(1) = 1 //initializing base conditions

3.for(i = 2 to i = n, i++) do{

4.fib(i) = fib(i - 1) + fib(i - 2);

5.}

Explanation

This algo will use the basic concept of dynamic programming that is memoization and optimal substructure.In the first pseudocode same thing is being calculated over and over again thus increasing the complexity upto   and in dynamic programming implementation we didn't calculate same thing more than once thus complexity reduced to . Therefore dynamic programming implementation is more advantageous.


Related Solutions

Provide the dynamic-programming recurrence for a function that is used to solve 0-1 Knapsack. Clearly define...
Provide the dynamic-programming recurrence for a function that is used to solve 0-1 Knapsack. Clearly define what the function is computing.
Solve the following problem by Dynamic Programming: Maximize z = (y1 + 2)^2 + y2 *...
Solve the following problem by Dynamic Programming: Maximize z = (y1 + 2)^2 + y2 * y3 + (y4 - 5)^2 subject to y1 + y2 + y3 + y4 <= 5 yi >= 0 and integer, i = 1, 2, 3, 4
5. Design a dynamic programming algorithm to solve the following problem. Input: An array A[1, ....
5. Design a dynamic programming algorithm to solve the following problem. Input: An array A[1, . . . , n] of positive integers, an integer K. Decide: Are there integers in A such that their sum is K. (Return T RUE or F ALSE) Example: The answer is TRUE for the array A = [1, 2, 3] and 5, since 2 + 3 = 5. The answer is FALSE for A = [2, 3, 4] and 8. Note that you...
Problem 2. Purpose: practice algorithm design using dynamic programming. A subsequence is palindromic if it is...
Problem 2. Purpose: practice algorithm design using dynamic programming. A subsequence is palindromic if it is the same whether read left to right or right to left. For instance, the sequence A,C,G,T,G,T,C,A,A,A,A,T,C,G has many palindromic subsequences, including A,C,G,C,A and A,A,A,A (on the other hand, the subsequence A,C,T is not palindromic). Assume you are given a sequence x[1...n] of characters. Denote L(i,j) the length of the longest palindrome in the substring x[i,...,j]. The goal of the Maximum Palindromic Subsequence Problem (MPSP)...
Implementation in CLIPS programming language for the following problem Acme Electronics makes a device called the...
Implementation in CLIPS programming language for the following problem Acme Electronics makes a device called the Thing 2000. This device is available in five different models distinguished by the chassis. Each chassis provides a number of bays for optional gizmos and is capable of generating a certain amount of power. The following table sumarizes the chassis attributes: Chassis --------- Gizmo Bays provided --- Power Provided----- Price($) C100--------------------------- 1--------------------------- 4------------------ 2000 C200------------------------- 2 -------------------------- 5------------------ 2500 C300--------------------------- 3---------------------------7 ------------------3000 C400---------------------------2----------------------------8------------------ 3000...
Recall the dynamic programming algorithm we saw in class for solving the 0/1 knapsack problem for...
Recall the dynamic programming algorithm we saw in class for solving the 0/1 knapsack problem for n objects with a knapsack capacity of K. In particular, we characterized our recurrence OPT(j, W) to be following quantity: OPT(j, W) := The maximum profit that can be obtained when selecting from objects 1, 2, . . . , j with a knapsack capacity of W , where (after filling in our dynamic programming table), we return the value stored at OPT(n, K)...
Using C++ use dynamic programming to list first 30 Fibonacci numbers. Fibonacci sequence is famous problem...
Using C++ use dynamic programming to list first 30 Fibonacci numbers. Fibonacci sequence is famous problem solved with recursion. However, this can also be done more efficiently using dynamic programming. Create a program that uses dynamic programming techniques to list the first 30 Fibonacci numbers.
Can you please solve this using recursion/ dynamic programming? Any programming language is fine. Wallace the...
Can you please solve this using recursion/ dynamic programming? Any programming language is fine. Wallace the Weightlifting Walrus is training for a contest where it will have to lift 1000 kg. Wallace has some weight plates lying around, possibly of different weights, and its goal is to add some of the plates to a bar so that it can train with a weight as close as possible to 1000 kg. In case there exist two such numbers which are equally...
Recursion is a programming technique in which a function calls itself. This project applies recursion to a new problem, and illustrates the recursive implementation of backtracking.
RECURSIVELY FINDING PATHS THROUGH A MAZE in C++INTRODUCTIONRecursion is a programming technique in which a function calls itself. This project applies recursion to a new problem, and illustrates the recursive implementation of backtracking.DESCRIPTIONConsider finding all paths from an entrance on the top of a maze to an exit on the bottom. This task can be accomplished recursively, so in this project, you design, implement, test, and document a program that calls a recursive function to find a path through a maze.An...
Be sure to clearly state the hypotheses in the hypothesis tests and state the conclusions in...
Be sure to clearly state the hypotheses in the hypothesis tests and state the conclusions in terms of the problem. Use ?=.?? for all tests. The following table presents shear strength (in kN/mm) and weld diameters (in mm) for a sample of spot welds. Diameter Strength 4.2                51 4.4                54 4.6               69 4.8                81 5.0                75 5.2               79 5.4                89 5.6               101 5.8                98 6.0               102 1.Construct a scatterplot of strength (y) versus diameter (x). Does it appear as though...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT