Docsity

4 Problems Assignment 6 - Analysis of Algorithms | CS 325, Assignments of Algorithms and Programming

Toggle sidebar
bg1
HW6 CS325 Due date: 02/23
Problem 1. Apply Bellman-Ford algorithm to the following graph, starting at node S.
(a) Draw the table showing all the d(i, v) values for i=0, …, n-1 and every node v in
the graph.
(b) Show the final shortest-path tree.
Problem 2. Knapsack Problem with no repetitions.
Consider the following knapsack problem:
W=10 and
Solve this problem using the dynamic programming algorithm presented in class. Please
show the two dimensional table K(w, j) for w= 0, 1, …, W and j = 1,2,3,4.
pf2

Partial preview of the text

Download 4 Problems Assignment 6 - Analysis of Algorithms | CS 325 and more Assignments Algorithms and Programming in PDF only on Docsity!

HW6 CS325 Due date: 02/

Problem 1. Apply Bellman-Ford algorithm to the following graph, starting at node S.

(a) Draw the table showing all the d(i, v) values for i=0, …, n-1 and every node v in the graph. (b) Show the final shortest-path tree.

Problem 2. Knapsack Problem with no repetitions. Consider the following knapsack problem:

W=10 and

Solve this problem using the dynamic programming algorithm presented in class. Please show the two dimensional table K( w , j ) for w = 0, 1, …, W and j = 1,2,3,4.

Problem 3. A contiguous subsequence of a list S is a subsequence made up of consecutive elements of S. For instance, if S is [5, 15, -30, 10, -5, 40, 10] then [15, -30, 10] is a contiguous subsequence but [5, 15, 40] is not. The maximum contiguous subsequence is defined as follows. Given S, a list of numbers a 1 , a 2 , …, an, find the contiguous subsequence of S whose sum is maximized. Design a dynamic programming algorithm to solve this problem. [Hint: Let OPT( i ) denote the maximum sum you can get by using a contiguous subsequence that ends at element i. Can you express OPT( i ) in terms of OPT( i ’) for smaller i ’? What is the best solution once you know OPT( i ) for i =0, 1, 2, …, n?]

Problem 4. Give an O(nt) algorithm to answer the following question: Input: a list of n positive integers a 1 , a 2 , …, an ; a positive integer t. Question: Does some subset of the ai ’s add up to t? (each ai can be used at most once).