算法设计与分析(实验班) Assignment 11

本文也可在我的知乎我的博客园上阅读。

1 Search and Decision Problems

As discussed in class, NP is a class of decision problems, i.e., the answer is either “yes” or “no”. This choice is convenient and often also captures the difficulty of searching for a solution. In our class, we have shown the reduction from search to decision for some problems. Here, you will show the search-to-decision reduction for two more examples.

(1)

3-SAT: A 3-SAT formula consists of m m m clauses, each of which is a disjunction of three literals (where a literal is one of n n n variables or its negation). We say a 3-SAT formula F F F is satisfiable if there is an assignment of the n n n variables such that F F F evaluates to true. The 3-SAT problem asks us to decide whether a given F F F is satisfiable.

Suppose you are given a black box for a function 3 S A T \sf{3SAT} 3SAT that determines whether a given 3-SAT formula is satisfiable with timing cost T 3 S A T T_{\sf{3SAT}} T3SAT. Design an algorithm that finds a satisfying assignment for F F F (assuming it is satisfiable) using O ( n ) O(n) O(n) calls to 3 S A T \sf{3SAT} 3SAT and polynomially many other steps. Prove that your algorithm is correct and analyze its running time.

逐一赋值并检查即可。

设这 n n n 个变量为 X 1 , X 2 , … , X n X_1, X_2, \ldots, X_n X1,X2,,Xn

首先,测试 X 1 = t r u e X_1 = {\sf true} X1=true 时原问题是否有解。具体来说,是询问 F ∧ ( X 1 ∨ X 1 ∨ X 1 ) F \land (X_1 \lor X_1 \lor X_1) F(X1X1X1) 是否有解。如果有,则令 X 1 : = 1 , F : = F ∧ ( X 1 ∨ X 1 ∨ X 1 ) X_1 := 1, F := F \land (X_1 \lor X_1 \lor X_1) X1:=1,F:=F(X1X1X1),求 X 2 X_2 X2 的值。否则,若没有解,则令 X 1 = 0 X_1 = 0 X1=0 F : = F ∧ ( X 1 ‾ ∨ X 1 ‾ ∨ X 1 ‾ ) F := F\land (\overline{X_1} \lor \overline{X_1}\lor \overline{X_1}) F:=F(X1X1X1),求 X 2 X_2 X2 的值。以此类推即可。

(2)

3-Coloring: We say an undirected graph is 3-colorable if there is an assignment of the colors { r , g , b } \{r, g, b\} {r,g,b} to the vertices (a coloring) such that no two adjacent vertices have the same color. The 3-Coloring problem asks us to decide whether a given graph is 3-colorable.

Suppose you are given a black box for a function 3 C o l o r \sf 3Color 3Color that determines whether a given graph is 3-colorable with timing cost T 3 C o l o r T_{\sf 3Color} T3Color. Design an algorithm that finds a coloring of a given graph using O ( n ) O(n) O(n) calls to 3 C o l o r \sf 3Color 3Color and polynomially many other steps, where n n n is the number of vertices in the input graph. Prove that your algorithm is correct and analyze its running time.

逐一赋值并检查即可。

具体来说,设点的颜色为 X 1 , X 2 , … , X n X_1, X_2, \ldots, X_n X1,X2,,Xn。不妨设 X 1 , X 2 X_1, X_2 X1,X2 有连边,设 X 1 = r , X 2 = g X_1 = r, X_2 = g X1=r,X2=g

  • 首先,测试 X 3 = r X_3 = r X3=r 时原问题是否有解。具体来说,是在图 G G G 增加点 u , v u, v u,v 与边 ( X 1 , u ) , ( X 1 , v ) , ( u , v ) , ( u , X 3 ) , ( v , X 3 ) (X_1, u), (X_1, v), (u, v), (u, X_3), (v, X_3) (X1,u),(X1,v),(u,v),(u,X3),(v,X3),得到图 G ′ G' G。很明显,这与令 X 3 = X 1 X_3 = X_1 X3=X1 是等价的。如果有解,则令 G : = G ′ G := G' G:=G,继续求 X 4 X_4 X4

    X1
    u
    v
    X3

  • 否则,测试 X 3 = g X_3 = g X3=g 时原问题是否有解,方法与上面类似。

  • 若还是无解,则有 X 3 = b X_3 = b X3=b,对原图 G G G 添加这些边 ( X 1 , X 3 ) , ( X 2 , X 3 ) (X_1, X_3), (X_2, X_3) (X1,X3),(X2,X3),得到 G ′ G' G。这与添加约束 X 3 ≠ X 1 , X 3 ≠ X 2 X_3 \ne X_1, X_3 \ne X_2 X3=X1,X3=X2 等价(相当于令 X 3 = b X_3 = b X3=b)。之后,令 G : = G ′ G := G' G:=G,继续求 X 4 X_4 X4 即可。

    X1
    X3
    X2

显然,上面的过程至多调用了 2 ( n − 2 ) 2(n-2) 2(n2) 3 C o l o r \sf 3Color 3Color,对原图添加至多 2 ( n − 2 ) 2(n-2) 2(n2) 个点, 5 ( n − 2 ) 5(n-2) 5(n2) 条边,符合要求。

2 3-Dimensional Matching

In our class, we introduced how to solve the bipartite matching problem in polynomial time. In particular, the perfect bipartite matching problem can be written in the following way: Suppose we are given two disjoint sets A A A and B B B, each of size n n n, and a set P P P of pairs drawn from A × B A × B A×B. The goal is to determine whether there exists a set of n n n pairs in P P P such that each element in A ∪ B A ∪ B AB is contained in exactly one of these pairs.

As a generalization, consider the following 3 3 3-dimensional matching problem: Suppose we are given three disjoint sets A A A, B B B, and C C C, each of size n n n, and a set T T T of triples drawn from A × B × C A × B × C A×B×C. The goal is to determine whether there exists a set of n n n triples in T T T such that each element in A ∪ B ∪ C A ∪ B ∪ C ABC is contained in exactly one of these triples.

(1)

Prove that 3-dimensional-matching ≤ P ≤_P P Set-Cover. This implies that 3-dimensional-matching ∈ ∈ NP.

这是显然的。下面叙述如何利用集合覆盖问题求解一个3维完美匹配问题。

首先,若 ⋃ T ≠ A ∪ B ∪ C \bigcup T \ne A\cup B \cup C T=ABC,则显然没有3维完美匹配。

直接对 T T T 求解覆盖集合问题,若 A ∪ B ∪ C A\cup B\cup C ABC 能被 n n n 个集合 X 1 , X 2 , … , X n X_1, X_2, \ldots, X_n X1,X2,,Xn 覆盖,则这些集合 X 1 , X 2 , … , X n X_1, X_2, \ldots, X_n X1,X2,,Xn 显然是一个3维完美匹配。

否则,若 A ∪ B ∪ C A\cup B\cup C ABC 不能被 n n n 个集合 X 1 , X 2 , … , X n X_1, X_2, \ldots, X_n X1,X2,,Xn 覆盖,则 T T T 显然不存在3维完美匹配。

(2)

Prove that 3-SAT ≤ P ≤_P P 3-dimensional-matching. Together with (1), this implies that the 3-dimensional-matching problem is NP-complete.

本部分大量参考了CMSC 451: More NP-completeness Results,图也都截自此。

考虑如何将 3-SAT 问题化归为3维覆盖问题:

  1. 对每个 3-SAT 问题里的变量 X i X_i Xi,建立一个构件(gadget),如图。

    具体来说,创建一个共有 2 k 2k 2k 个点的“核” A i = { a i , 1 , … , a i , 2 k } A_i = \{a_{i,1}, \ldots, a_{i,2k}\} Ai={ai,1,,ai,2k} 以及一个共有 2 k 2k 2k 个点的“尖端” B i = { b i , 1 , … , b i , 2 k } B_i = \{b_{i,1},\ldots,b_{i,2k}\} Bi={bi,1,,bi,2k}

    最后,构造 2 k 2k 2k 个三元组 t i j = ( a i , j , a i , j + 1 , b i , j ) t_{ij} = (a_{i,j}, a_{i,j+1}, b_{i,j}) tij=(ai,j,ai,j+1,bi,j)

    (本构造中直接令 k = k = k= 3-SAT 问题中分句的数量 m m m

    这一步共构造了 4 n k 4nk 4nk 个点, 2 n k 2nk 2nk 个集合。

    这个构件有什么意义?

    每一个这样的构件在3维完美匹配中,“核”的点是匹配奇数尖端 b i , 1 , b i , 3 , … b_{i,1}, b_{i,3}, \ldots bi,1,bi,3, 还是匹配偶数尖端 b i , 2 , b i , 4 , … b_{i,2},b_{i,4},\ldots bi,2,bi,4, 分别代表 3-SAT 问题中 X i X_i Xi 是取真还是取假(如图)

    (很明显,如果所有“核”的点都有匹配,那么肯定要么全部匹配奇数尖端,要么匹配偶数尖端)

    我们规定,匹配奇数尖端(空出偶数尖端)代表 X i = t r u e X_i = {\sf true} Xi=true(图1),匹配偶数尖端(空出奇数尖端)代表 X i = f a l s e X_i = {\sf false} Xi=false(图2)。

  2. 对每个 3-SAT 问题里的分句(clause) C i C_i Ci,创建两个点 c i , c i ′ c_i, c_i' ci,ci,并且对所有在这个分句里的变量 X j X_j Xj,如果是以肯定形式 X j X_j Xj 出现的,那么构造集合 { c i , c i ′ , b j , 2 i } \{c_i, c_i', b_{j,2i}\} {ci,ci,bj,2i}。否则,如果是以肯定形式 X j ˉ \bar{X_j} Xjˉ 出现的,则构造集合 { c 1 , c 1 ′ , b j , 2 i − 1 } \{c_1, c_1', b_{j,2i-1}\} {c1,c1,bj,2i1}

    例如,假设有 C 1 = X 1 ∨ X 3 ‾ ∨ X 5 ‾ C_1 = X_1 \lor \overline{X_3} \lor \overline{X_5} C1=X1X3X5,先创建两个点 c 1 , c 1 ′ c_1, c_1' c1,c1,并构造三元集合 { c 1 , c 1 ′ , b 1 , 2 } , { c 1 , c 1 ′ , b 3 , 1 } , { c 1 , c 1 ′ , b 5 , 1 } \{c_1, c_1', b_{1,2}\}, \{c_1, c_1', b_{3,1}\}, \{c_1, c_1', b_{5,1}\} {c1,c1,b1,2},{c1,c1,b3,1},{c1,c1,b5,1}。(如图)

    这样, { c 1 , c 1 ′ } \{c_1, c_1'\} {c1,c1} 匹配哪个构件的点 b j , ∗ b_{j,*} bj, 就代表对应变量 X j X_j Xj 的赋值满足 3-SAT 中分句的要求。

    这一步共构造了 2 m 2m 2m 个点, 3 m 3m 3m 个集合。

  3. 还有一个细节:

    我们注意到,有很多尖端(具体来说是 n k − m nk - m nkm 个)是不会被匹配的。为了让匹配成为完美匹配,需要对每个尖端 b b b 构造“清理小装置” { q i , q i ′ , b } \{q_i, q_i', b\} {qi,qi,b},其中 i = 1 , 2 , … , n k − m i = 1, 2,\ldots, nk-m i=1,2,,nkm

    这一步共构造了 2 ( n k − m ) 2(nk-m) 2(nkm) 个点, k ( n k − m ) k(nk-m) k(nkm) 个集合。

这样,我们把 3-SAT 问题在多项式时间内化归为了多项式规模的 3维完美匹配问题(3-SAT 问题有解    ⟺    \iff 3维完美匹配问题有解)。 ■ \blacksquare

3 Restricted Monotone Satisfiability

Consider an instance of the Satisfiability problem, specified by clauses C 1 , . . . , C k C_1, . . . , C_k C1,...,Ck over a set of Boolean variables x 1 , . . . , x n x_1 , . . . , x_n x1,...,xn . We say that the instance is monotone if each literal is a non-negated variable (i.e., x i x_i xi can appear as a literal but ¬ x i ¬x_i ¬xi cannot). Monotone instances are always satisfiable since we can simply set each variable to 1 1 1.

For example, suppose we have the three clauses
( x 1 ∨ x 2 ) , ( x 1 ∨ x 3 ) , ( x 2 ∨ x 3 ) (x_1 ∨ x_2), (x_1 ∨ x_3),(x_2 ∨ x_3) (x1x2),(x1x3),(x2x3)
This is monotone, and indeed the assignment that sets all three variables to 1 1 1 satisfies all the clauses. But we can observe that this is not the only satisfying assignment; we could also have set x 1 x_1 x1 and x 2 x_2 x2 to 1 1 1, and x 3 x_3 x3 to 0 0 0. Indeed, for any monotone instance, it is natural to ask how few variables we need to set to 1 1 1 in order to satisfy it.

Given a monotone instance of Satisfiability, together with a number k k k, the problem of Restricted Monotone Satisfiability asks: is there a satisfying assignment for the instance in which at most k k k variables are set to 1 1 1? Prove this problem is NP-complete.

首先,证明它是 NP 的:考虑将该问题化归为集合覆盖问题

对将每一个变量 x i x_i xi,构造它所对应的集合 X i = { C j ∣ x i 出现在子句 C j 中 } X_i = \{C_j \mid x_i 出现在子句 C_j 中\} Xi={Cjxi出现在子句Cj} x i x_i xi 为真相当于满足了 X i X_i Xi 中所有子句的约束(“覆盖”了 X i X_i Xi 中的所有子句 C j C_j Cj)。

这样,原问题可以看作在集合 C C C 上的一个集合覆盖问题:

给定全集 C = { C 1 , … , C k } C = \{C_1, \ldots, C_k\} C={C1,,Ck} 与它的子集构成的集合 X = { X 1 , … , X n } X = \{X_1, \ldots, X_n\} X={X1,,Xn},求是否存在一个大小为 k k k 的集合覆盖。

若此集合覆盖问题有解,则它的解对应原问题的一个解。若此集合覆盖问题无解,则原问题也无解。

我们可以用同样的方法把集合覆盖问题化归为此问题,因而它是 NP-Complete的。 ■ \blacksquare

4 Do some Calculus!

For functions g 1 , . . . , g l g_1,...,g_l g1,...,gl, we define the function max ⁡ ( g 1 , . . . , g l ) \max(g_1,...,g_l) max(g1,...,gl) via
[ max ⁡ ( g 1 , . . . , g l ) ] ( x ) = max ⁡ ( g 1 ( x ) , . . . , g l ( x ) ) [\max(g_1,...,g_l)](x) = \max(g_1(x),...,g_l(x)) [max(g1,...,gl)](x)=max(g1(x),...,gl(x))
Consider the following problem. You are given n n n piecewise linear, continuous functions f 1 , . . . , f n f_1 , . . . , f_n f1,...,fn defined over the interval [ 0 , t ] [0, t] [0,t] for some integer t t t. You are also given an integer B B B. You want to decide: do there exist k k k of the functions f i 1 , . . . , f i k f_{i_1},...,f_{i_k} fi1,...,fik so that
∫ 0 t [ max ⁡ ( f i 1 , . . . , f i k ) ] ( x ) d x ≥ B \int^t_0 [\max(f_{i_1},...,f_{i_k})](x) \mathrm{d} x ≥ B 0t[max(fi1,...,fik)](x)dxB
Prove that this problem is NP-complete.

首先,证明它是 NP 的:它的解可以在多项式时间( O ( n 2 m 2 ) O(n^2m^2) O(n2m2),其中 m m m f i f_i fi 的段数上界)内验证,所以它是 NP 的。

之后,证明它是 NP-Complete 的:利用第 3 题的结论,只需证明可以将 Restricted Monotone Satisfiability 问题化归为它。

构造函数
f i ( x ) = { 1 , j ≤ x < j + 1 , j ∈ N ∗ , x 出现在子句 C j 中 0 , 其他 f_i(x) = \begin{cases} 1, & j\le x < j+1, j\in \mathbb N^*, x \text{出现在子句}C_j\text{中} \\ 0, & \text{其他} \end{cases} fi(x)={1,0,jx<j+1,jN,x出现在子句Cj其他
显然,
[ max ⁡ ( f i 1 , . . . , f i k ) ] ( x ) = { 1 , j ≤ x < j + 1 , j ∈ N ∗ , ∃ x i l 出现在子句 C j 中 0 , 其他 [\max(f_{i_1},...,f_{i_k})](x) = \begin{cases} 1, & j\le x < j+1, j\in \mathbb N^*, \exists x_{i_l} \text{出现在子句}C_j\text{中} \\ 0, & \text{其他} \end{cases} [max(fi1,...,fik)](x)={1,0,jx<j+1,jN,xil出现在子句Cj其他
因此,原问题的解和 Restricted Monotone Satisfiability 问题的解是一一对应的。故原问题是 NP-Complete 问题。 ■ \blacksquare

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值