0% found this document useful (0 votes)
17 views

CS300 Assignment6

Uploaded by

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

CS300 Assignment6

Uploaded by

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

20230672

Yunajeong
Assignment 6 Due: 2024.06.02 23:59:00
2024 Spring CS300 TA: Kyounga Woo ([email protected])

• Please submit before the submission deadline.

• Assignment submitted one (1) day after the assignment deadline will be accepted with 20%
deduction on corresponding assignment grade.
• Assignment submitted more than one (1) day late will not be accepted.

Problem 1: Chain Matrix Problem (35 points)


Below is the chain matrix multiplication algorithm.

Algorithm 1 Chain Matrix Multiplication Algorithm


1: for i = 1 to n
2: C(i, i) = 0
3: for s = 1 to n 1
4: for i = 1 to n s
5: j =i+s
6: C(i, j) = min{C(i, k) + C(k + 1, j) + mi 1 mk mj }, where i  k < j
7: return C(1, n)

Using algorithm 1, you are going to solve the minimum cost for chain matrix multiplication for
five matrices, A1 . . . A5 .
The size of the matrices are given as follows:

A1 = 2 ⇥ 9, A2 = 9 ⇥ 30, A3 = 30 ⇥ 6, A4 = 6 ⇥ 7, A5 = 7 ⇥ 4

(a) (30 points) Calculate the subtree C(i, j) and the split point k by filling the tables. The class
lecture (“example” VOD on week 11) will be helpful to fill the table.

(1) The table 1, denotes the number of the matrix multiplications for each subtree C(i, j),
where C(i, j) = number of matrix multiplications of j i (2 points per each blank).

C(i, j) j = 1 j=2 j=3 j=4 j=5


i=1 0 tG40 aOo a84 COCO
i=2 - 0 1620 laa8 labf
i=3 - - 0 1260 888
i=4 - - - 0 168
i=5 - - - - 0

Table 1: Subtree C(i, j) for multiplying matrices

(2) The table 2 is the last split point k when combining two subtree (1 point per each
blank).

k(i, j) j=2 j=3 j=4 j=5


i=1 ( 2

i=2
i=3
-
-
2
- 률
i=4 - - - 료
Table 2: Split point K(i, j) for multiplying matrices

1
20230672
Yunajeong
Assignment 6 Due: 2024.06.02 23:59:00
2024 Spring CS300 TA: Kyounga Woo ([email protected])

Use this space to calculate the value for C(i, j).

(b) (3 points) Write down the minimum cost and the corresponding optimal parenthesization.

Minimum cost: (O40 ,

π(
Optimal Parenthesization: A1 A)2 A3 A4 A5
) ) ) d
(c) (2 points) What is the running time for algorithm 1?
(a) O(n)
(b) O(n2 )
(c) O(n2 log(n))
V
(d) O(n3 )

2
20230672
Yunajeong

Assignment 6 Due: 2024.06.02 23:59:00


2024 Spring CS300 TA: Kyounga Woo ([email protected])

Problem 2: Floyd-Warshall Algorithm (25 points)


Below is the Floyd-Warshall algorithm.

Algorithm 2 Floyd-Warshall Algorithm


1: for i = 1 to n
2: for j = 1 to n
3: dist(i, j) = 1
4: for all (i, j) 2 E
5: dist(i, j) = l(i, j)
6: for k = 1 to n
7: for i = 1 to n
8: for j = 1 to n
9: dist(i, j) = min{dist(i, k) + dist(k, j), dist(i, j)}

(Each blank 0.25 point) For below graph, apply algorithm 2 and fill the matrices. The outermost
loop visits vertex in an alphabetical order. The initialized matrix is given to you. The edge
direction is from the row to the column.

Initialized matrix Apply vertex A


MI A B C D E MA A B C D E
A 0 1 1 1 1 A 0
B
C 1
3 0
4
1
0
2
1
1
1
B
C
종용 ‰ 0 " 임
0 1
1 1
⑥ ∞
D 6 0 3 D 0 β
E 1 2 1 1 0 E 0

Apply vertex B Apply vertex C

MB A B C D E MC A B C D E
A 0 ∞ I g ∞ A 0 5 ∞
12
0
B 3 0 2 2 ∞ - -
B 3 0 -
3 ∞
C 1 4 0 - ∞ C 1 4 0 ㅓ ∞

D n 0 3 D 6 0 3
1 얼
6 ∞

E L O ㆁ 0 E - o 0

3
20230672
Yunajeong
Assignment 6 Due: 2024.06.02 23:59:00
2024 Spring CS300 TA: Kyounga Woo ([email protected])

Apply vertex D Apply vertex E

MD A B C D E ME A B C D E
A 0 5 1 O 3 A 0 ω
B 3 0
C
D 6
1 4 0
∞ 서
- α O

0
O
2
B
B
C
D
-

5
β 0
4 층으로 홀
0
0
O
E ㆁ 0 E -
1 L O 0

4
20230672
Yunajeong

Assignment 6 Due: 2024.06.02 23:59:00


2024 Spring CS300 TA: Kyounga Woo ([email protected])

Problem 3: Independent Set (12 points)


(a) (3 points) Find the largest independent set for below graph. If vertices v1 . . . vn is in the
independent set, the answer form should be {v1 , . . . , vn }.

Independent Set: EQ , 4 , 7173

(b) (3 points) Assuming P 6= NP, what is the running time of the optimal algorithm finding a
maximum independent set of a graph? (4)
(1) O(n)
(2) O(n log n)
(3) O(n2 )

(4) None of above.
(c) (3 points) Find the largest independent set for below tree. If there are multiple largest inde-
pendent set, write one of them.

Independent Set: ST . T . 617 , 8 93


,

(d) (3 points) Assuming P 6= NP, what is the running time of the optimal algorithm finding a
maximum independent set of a tree? ( ?


(1) O(n)
(2) O(n log n)
(3) O(n2 )
(4) None of above.

5
20230672
Yunajeong

Assignment 6 Due: 2024.06.02 23:59:00


2024 Spring CS300 TA: Kyounga Woo ([email protected])

Problem 4: NP (18 points)


(a) (6 points) For following statements, answer

True if the statement agrees with the information,


False if the statement contradicts with the information.
No justification is needed for the answer.

(1) Every decision problem in P is in NP and co-NP Ealse


(2) An algorithm which checks if some formula is a tautology is not in co-NP. crue
(3) If NP 6= co-NP, then P 6= NP crue

(b-c) The formula satisfiability problem (SAT) is a boolean formula that consists variables
(x1 , x2 , . . . ), operators (¬, ^, _, =) ), and parentheses. You are going to show that SAT is a
NP-complete.

(b) (5 points) Demonstrate that SAT belongs to NP in one sentence.

SAT pooblem belongs to NP because gTven a boolean formula ,

vevifyrng whetheragven valricabieassgent satesfres

the forouulg be done


can - n
polyuomcal tone .

(c) (7 points) Show that SAT is NP-hard by reducing the circuit satisfiability problem. Include
the preprocess, application of the algorithm, and postprocess when performing reduction.

oshowtuatSAT또 NP-
hart , we reduce the civcut
satsfcablityproblem [ CircuiTSAr )toSA

process -GTven abooleancFrcurt C , we coustrut

equivalent booleanformula .his uvolves


ding
an 4
enco

the behavcor of the crcuct using booleau varcables

and logccal operators .

You might also like