Uploaded by IVIahdi

221ICS353Assignment4

advertisement
King Fahd University of Petroleum and Minerals
Information and Computer Science Department
ICS 353: Design and Analysis of Algorithms
Homework Assignment #4
(Due Saturday November 26, 2022 at midnight)
PART A: Solve and submit solutions to Questions I-IV.
Question I (25 points): Consider the following two strings:
𝐴 = 𝑎𝑑𝑎𝑐𝑎𝑑𝑎𝑏𝑟𝑎
𝐵 = 𝑐𝑎𝑑𝑎𝑟𝑑𝑏𝑎
1) (19 points) Apply the Longest Common Subsequence algorithm, LCS to find the length of the
longest common subsequence between 𝐴 and 𝐵. Include the whole table.
2) (6 points) Derive all longest common subsequences from your solution in 1).
Question II (25 points): Consider applying the Matrix Chain Multiplication Algorithm on the
following five matrices:
𝑀1 : 7 × 4
𝑀2 : 4 × 6
𝑀3 : 6 × 9
𝑀4 : 9 × 3
𝑀5 : 3 × 5
1) (20 points) Find the minimum number of scalar multiplications needed to multiply the five
matrices, 𝐶 [1, 5]. Show all your calculations.
2) (5 points) Find the optimal parenthesizing corresponding to the optimal value found in part 1.
Question III (25 points): Another version of the knapsack problem is to let the set U contain a set of
types of items, and the objective is to fill the knapsack with any number of items of each type in
order to maximize the total value without exceeding the knapsack capacity. Assume that there is an
unlimited number of items of each type. More formally, let 𝑇 = {𝑡1 , 𝑡2 , . . . , 𝑡𝑛 } be a set of n types of
items, and C the knapsack capacity. For 1 ≤ j ≤ n, let 𝑠𝑗 and 𝑣𝑗 be, respectively, the size and value of
the items of type j. Find a set of nonnegative integers 𝑥1 , 𝑥2 , … , 𝑥𝑛 such that
𝑛
∑ 𝑥𝑖 𝑣𝑖
𝑖=1
is maximized, subject to the constraint
𝑛
∑ 𝑥𝑖 𝑠𝑖 ≤ 𝐶
𝑖=1
where 𝑥1 , 𝑥2 , … , 𝑥𝑛 are nonnegative integers. Note that 𝑥𝑗 = 0 means that no item of the jth type is
packed in the knapsack.
1) (13 points) Rewrite the dynamic programming formula for this version of the knapsack problem.
2) (12 points) Solve the following instance of this version of the knapsack problem. There are four
types of items with sizes 2, 3, 5, and 6 and values 4, 7, 9, and 11, respectively, and the knapsack
capacity is 10.
Hint: Try to solve part b in order to help you in solving part a.
Question IV (25 points): Assuming that the problem VERTEX COVER is NP-Complete, show that
Problem CLIQUE is NP-Complete.
PART B: Solve but DO NOT submit solutions to the following questions.
Question V: Run the all-pairs shortest path algorithm on the weighted directed graph shown below.
12
16
a
b
6
5
3
d
c
3
2
2 4
9
8
e
Question VI: Consider the following Boolean formula
f = ( x 1  x 2  x 3  x 4 )  (x 1  x 2  x 3 )  (x 2  x 4 )
1) Transform this input to the Satisfiability problem into an instance of the VERTEX COVER
decision problem using the polynomial transformation that we developed in class.
2) Find a vertex cover of minimum size of the graph in "1)".
3) Transform this input to the Satisfiability problem into an instance of the CLIQUE decision
problem using the polynomial transformation that we developed in class.
4) Find a clique of maximum size of the graph in 3).
Question VII: Let Π1 and Π2 be two problems such that Π1 ∝𝑝𝑜𝑙𝑦 Π2 . Suppose that problem Π2
can be solved in 𝑂(𝑛𝑘 ) time and the reduction can be done in 𝑂(𝑛𝑗 ) time. Show that problem Π1
can be solved in 𝑂(𝑛𝑗𝑘 ) time.
Download