0% found this document useful (0 votes)
32 views3 pages

Assignment-1: PMSCS 616: Algorithm Analysis & Design

The document provides solutions to two algorithm analysis problems. For the 0-1 knapsack problem with capacity 7, the optimal solution is to include items 2, 4, and 5, with a total price of 50. This is shown through a 5x7 matrix tracking cumulative prices. For the longest common subsequence of strings "AGGTAB" and "GXTXAYB", the LCS is "GTAB" of length 4. This is shown through an 8x8 matrix tracking character matches and arrows indicating the path to the solution.

Uploaded by

Mahmuda Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views3 pages

Assignment-1: PMSCS 616: Algorithm Analysis & Design

The document provides solutions to two algorithm analysis problems. For the 0-1 knapsack problem with capacity 7, the optimal solution is to include items 2, 4, and 5, with a total price of 50. This is shown through a 5x7 matrix tracking cumulative prices. For the longest common subsequence of strings "AGGTAB" and "GXTXAYB", the LCS is "GTAB" of length 4. This is shown through an 8x8 matrix tracking character matches and arrows indicating the path to the solution.

Uploaded by

Mahmuda Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PMSCS 616: Algorithm Analysis & design

ASSIGNMENT-1

Submitted by__
Mahmuda Rahman
ID: CSE 202001027

Question-1: Compute the optimal price for the 0-1 knapsack problem for knapsack capacity, W=7.
Which items will be in the optimal solution? What will be their total price? Show how you calculate the
optimal solution using a matrix containing both price and arrows for each cell in the matrix.

Item 1 2 3 4 5
Weigh 1 2 3 3 2
t
Price 10 17 13 15 18

Solution:

Weight 0 1 2 3 4 5 6 7

Item
0
0 0 0 0 0 0 0 0

1
0 10 10 10 10 10 10 10

2
0 10 17 27 27 27 27 27

3
0 10 17 27 27 30 40 42

4
0 10 17 27 27 32 42 42

5
0 10 18 28 35 45 45 50

Here, {2,4,5} items are taken to get the optimal solution and their total price is 50.
Question-2: Compute the Longest Common Subsequence (LCS) of the strings X = "AGGTAB" and Y =
"GXTXAYB". Show how you calculated the LCS using a matrix containing both the cost and the arrows for
each cell in the matrix.

Solution:

Y G X T X A Y B

0 0 0 0 0 0 0 0

A
0 0 0 0 0 1 1 1

G
0 1 1 1 1 1 1 1

G
0 1 1 1 1 1 1 1

T
0 1 1 2 2 2 2 2

A
0 1 1 2 2 3 3 3

B 1
0 1 2 2 3 3 4

Here, the Longest Common Subsequence (LCS) of the strings X = "AGGTAB" and Y = "GXTXAYB" is
“GTAB” of length 4.

You might also like