CSC 323 Algorithm Design and Analysis, Spring 2013
Instructor: Dr. Natarajan Meghanathan Chapter 8 Dynamic Programming, Question Bank
1) There are a row of 6 coins of values {5, 1, 2, 10, 6, 2}; the objective is to pick up the maximum amount of money subject to the constraint that no two coins adjacent in the above list can be picked up. Develop a dynamic programming solution for this optimization problem You need to write the recurrence relation and provide step-by-step details of the solution.
F(n) = Max{ c n + F(n-2), F(n-1)} for n > 1 F(0) = 0; F(1) = c 1 .
The coins that need to be picked up to obtain the maximum sum of 17 are {C1 = 5, C4 = 10, C6 = 2}
2) There are a row of 8 coins of values {3, 1, 5, 2, 5, 4, 2, 3}; the objective is to pick up the maximum amount of money subject to the constraint that no two coins adjacent in the above list can be picked up. Develop a dynamic programming solution for this optimization problem You need to write the recurrence relation and provide step-by-step details of the solution.
The coins that need to be picked up to obtain the maximum sum of 16 are {C1 = 3, C3 = 5, C5 = 5, and C3 = 3} 2 3) Compute the binomial coefficient C(10, 7) using dynamic programming. Write the recurrence relation.
Recurrence: C(n,k) = C(n-1,k) + C(n-1,k-1) for n > k > 0 C(n,0) = 1, C(n,n) = 1 for n 0
4) Write the recurrence relations (including the initial conditions) and the time/space complexity for the following dynamic programming algorithms/problems discussed in class:
(a) Binomial Coefficients Problem: C(n,k) = C(n-1,k) + C(n-1,k-1) for n > k > 0 C(n,0) = 1, C(n,n) = 1 for n 0 Both Time and Space Complexity are: (nk).
(b) Coin Row Problem: Maximal value of coins selected from the list {c1, c2, ...., cn} is F(n) = Max{ c n + F(n-2), F(n-1)} for n > 1 F(0) = 0; F(1) = c 1 . Both Time and Space Complexity are: (n).
(c) Coin Selection Problem Let F(i, j) be the largest number of coins the robot can collect and bring to the cell (i, j) in the ith row and jth column of the board.
where c ij = 1 if there is a coin in cell (i, j) and c ij = 0 otherwise Both Time and Space Complexity are: (nm).
(d) Integer Knapsack Problem Let F(i, j) be the value of the most valuable subset of the first i items (1 i n) that fit into the knapsack of capacity j (1 j W). 3
Initial Condition: F(0, j) = 0 for 1 j W F(i, 0) = 0 for 1 i n Both Time and Space Complexity are: (nW), where n is the number of items in the list and W is the integer capacity of the knapsack.
5) Several coins are placed in cells of a 6 x 6 board (n x m board) shown below, with no more than one coin per cell. A robot, located in the upper left cell of the board, needs to collect as many of the coins as possible and bring them to the bottom right cell. On each step, the robot can move either one cell to the right or one cell down from its current location. When the robot visits a cell with a coin, it always picks up that coin.
Design a Dynamic Programming algorithm to find the maximum number of coins the robot can collect and a path it needs to follow to do this. You need to write the recurrence relation and clearly define all the terms/variables involved in it. Briefly explain how would you trace back your computation and determine the optimal path for the robot. Execute the above on the board.
Solution:
4 6) Find the composition of items that maximizes the value of the knapsack of integer capacity- weight 5. Also, write the recurrence relation.
Solution:
Recurrence relation:
7) Find the composition of items that maximizes the value of the knapsack of integer capacity- weight 6. Also, write the recurrence relation.
Solution:
Recurrence relation:
5
8) Run the Floyds algorithm on the following digraph and deduce the paths from v2 to v4 and vice-versa.
6
9) Run the Floyds algorithm on the following digraph (given its adjacency matrix) and deduce the paths from v1 to v3 and vice-versa.