F is the family of sets over a universe U, k is a positive integer. The task is to check whether there exists a subfamily F' \subseteq F of size k that covers U, which means that e
Algorithms··59 min read
By AkejyoOriginal writing
Parameterized algorithms
6.1.1 Parameterized algorithms
Set Cover
parameterized algorithms 6.1.1
F is the family of sets over a universe U, k is a positive integer. The task is to check whether there exists a subfamily F′⊆F of size k that covers U, which means that every element of U belongs to some set of F′.
TheoremGiven a Set Cover instance (U,F,k), the minimum possible size of a subfamily F′⊆F that covers U can be found in time 2∣U∣(∣U∣+∣F∣)O(1).
Proof. We define T[X,j] as the minimum possible size of a subset F′⊆{F1,F2,...,Fj} that covers X. If no such subset F′ exists, then T[X,j]=+∞. We compute all 2∣U∣(∣F∣+1) values T[X,j].
Let G be an undirected graph on n vertices and K⊆V(G) be a set of terminals, A Steiner tree for K in G is a connected subgraph H of G containing K, that is, K⊆V(H).
The goal of this section is to design a dynamic-programming algorithm for Stenier tree with running time 3∣K∣nO(1), where n=∣V(G)∣.
LemmaFor every D⊆K of size at least 2, and every v∈V(G)∖K, the following holds
T[D,v]=min{T[D′,u]+T[D∖D′,u]+dist(v,u)}
where T[D,v] means the minimum possible weight of a Steiner tree for D∪{v} in G, u∈V(G)∖K and ∅=D′⊊D
Similarly, for j=1, we should iterate through all the possible ways a maximum weight independent set intersects column Xj. This intersection should be independent, of course, and moreover if we pick some v∈Xj∖Y to the independent set, then this choice forbids choosing its neighbor in the previous column Xj−1 (providing this neighbor exists).
无论是哪种情况,计算量都在3k· kO(1)以内,最后时间复杂度3k · kO(1)·N.
7.2 Treewidth
Path decomposition
图 G 的一个路径分解是一个包 bag 的序列P=(X1,X2,...,Xr),满足:
(P1)⋃i=1rXi=V(G),即 G 的每个点都至少在一个包里.
(P2) 若边(u,v)属于G,那么存在一个 bag 同时包含了 u 和 v.
(P3) 若 u∈V(G),且u∈Xi∩Xk,i≤k,那么有u∈Xj,i≤j≤k.
路径分解的宽度width: max1≤i≤r∣Xi∣−1.
路径分解的路径宽度pathwidth ,即pw(G): the minimum possible width of a path decomposition of G.
Let us note that because of (P3), every vertex of G gets introduced and becomes forgotten exactly once in a nice path decomposition, and hence we have that r, the total number of bags, is exactly equal to 2\vertV(G)∣+1.
Lemma 2如果 G 存在宽度为 p 的路径分解,那么其也存在一个 nice 的宽度最大为 p 的路径分解。另外,给定 G 的宽度为 p 的路径分解P=(X1,X2,...,Xr),可在O(p2·max(r,∣V(G)∣))内求得 nice 的宽度 p 路径分解
Tree decompositions
树分解是路径分解的一个延伸
图 G 的一个树分解treedecomposition是一个pair T=(T,{Xt}t∈V(T)),其中 T 是一个树,树的每个节点 t 都分配有子点集 Xt⊆V(G),称为包 bag,遵循下面规则:
(T1)⋃t∈V(T)Xt=V(G),即图 G 的每个点都至少在一个包里.
(T2) 对于图 G 的每一条边 (u,v),都存在树 T 的一个节点 t 满足 Xt 同时包含了 u 和 v .
(T3) 对于图 G 的每一个点 u,集合 Tu={t∈V(T):u∈Xt},对应的包中包含 u 的节点集合,就得到了 T 的一个连通子树.
the set of nodes whose corresponding bags contain u, induces a connected subtree of T.
树分解的宽度width:maxt∈V(T)\vertXt∣−1
树分解的树宽度treewidth,即tw(G):is the minimum possible width of a tree decomposition of G.
Lemma 3设 T 是图 G 的一个树分解,ab 是 T 的一条边,那么森林 T−ab 包含了两个相连的部分 Ta(containinga),Tb(containingb). 设 A=⋃t∈V(Ta)Xt,B=⋃t∈V(Tb)Xt,那么就有 ∂(A),∂(B)⊆Xa∩Xb,同样(A,B)就是图 G 以 Xa∩Xb为separator的一个separation.
一个树分解是 nice 的,如果满足:
Xr=∅,Xℓ=∅,其中 r 是树 T 的根,ℓ 是树的每一个叶子.
任意不是叶子节点的节点都是下面三种类型之一:
Introducenode: 节点 t 恰好只有一个孩子 t′ 且有 Xt=Xt′∪{v},v∈/Xt′此时我们说v is introduced at t.
Forgetnode: 节点 t 恰好只有一个孩子 t′ 且有 Xt=Xt′∖{w},w∈Xt′,此时我们说w is forgotten at t
Joinnode: 节点 t 有两个孩子 t1,t2,且 Xt=Xt1=Xt2
Note also that, by property (T3) of a tree decomposition, every vertex of V(G) is forgotten only once, but may be introduced several times.
Lemma 4如果图 G 允许一个宽度至多为 k 的树分解,那么它也能做到一个宽度至多为 k 的 nice 树分解. 另外,给定图 G 的一个宽度为 k 的树分解 T=(T,{Xt}t∈V(T)),可以在 O(k2·max(\vertV(T)∣,\vertV(G)∣))内求得图 G 的一个宽度为 k 、拥有最多 O(k\vertV(G)∣)个节点的 nice 树分解
7.3.1 WeightedIndependentSet
设 T=(T,{Xt}t∈V(T)) 是 n 节点图 G 的一个树分解,宽度至多为 k,对于树上一节点 t,t=r,令 Vt为树 T 以 t 为根的子树里的包的并集,包括 Xt. 那么根据Lemma 7.3有 ∂(Vt)⊆Xt.
This exactly formalizes the intuition that the subgraph induced by Vt can communicate with the rest of the graph only via bag Xt, which is of small size.
this replacement preserves independence and can only increase the weight. Observe that the number of subproblems is small: for every node t, we have only 2∣Xt∣ subproblems. Also, we do not need to remember S^ explicitly; remembering its weight will suffice.
Recall that we are working on a tree decomposition of width at most k, which means that \vertXt∣≤k+1 for every node t. Thus at node t we compute 2∣Xt∣≤2k+1 values of c[t,S].
Wrapping up, for every node t it takes time 2k· kO(1) to compute all the values c[t,S]. Since we can assume that the number of nodes of the given tree decompositions is O(kn) (see Lemma 7.4), the total running time of the algorithm is 2k·kO(1)·n.
Theorem 7.5 给定一个有 n 个节点的带权图 G,同时给定它的宽度至多为 k 的树分解,那么 WeightedIndependentSet问题可以在 2k·kO(1)·n 时间内完成.
Corollary 7.6 给定一个有 n 个节点的带权图 G,同时给定它的宽度至多为 k 的树分解,那么 VertexCover问题可以在 2k·kO(1)·n 时间内完成.
Introduceedgenode: a node t, labeled with an edge uv ∈ E(G) such that u,v ∈ Xt, and with exactly one child t′ such that Xt=Xt′. We say that edge uv is introduced at t.
Theorem 7.7 给定一个 n 个节点的图 G 和它的宽度至多为 k 的树分解,DominatingSet 问题可以在 4k· kO(1)· n 内完成.
在第11章会介绍把 join node 计算时间从 4k 降到 3k.
7.3.3 Steiner Tree
这里了解Steiner Tree. 我们也会对图 G 做一个宽度至多为 k 的 nice 树分解,该树分解的定义方式和 7.3.2 里的一样,即带有 introduceedgenodes.
Single-exponential algorithm for Steiner Tree requires more advanced techniques that will be discussed in Chapter 11.
为了让接下来的算法更易解释,我们随机选择一个关键点 u∗∈K,并将 u∗ 添加到在 T 里的每一个包里. 这样处理后 T 的宽度将加一,根节点和叶子节点都是 {u∗}.
做一些规定:H 是连接了 K 的斯坦纳树,t 是 T 的节点. H 在 Gt 里的部分是一个有些许连通分量的森林 F. 由于 H 是连通的且 Xt 至少包含一个关键点,就会有 F 里的每一个连通分量都和 Xt 有交集的. 另外,K∩Vt 里的每一个关键点都应该属于 F 里的某些连通分量. 对于 Xt 的每一个子集 X 和 X 的每一个划分 P,Gt 里 F 的最小大小有:
F 有恰好 q 个连通分量,分别为 C1,...,Cq,因此对于每一个 s∈{1,...,q},有 Ps=V(Cs)∩Xt,于是就有 P 和 F 的连通分量是对应的.
Xt∩V(F)=X. 因此 Xt∖X 与 F 不相连.
K∩Vt 的每一个关键点都在 V(F) 里.
如果 F 符合上面,就说 F 是对 (t,X,P) 兼容的(compatible),如果没有兼容的 F 存在,就让 c[t,X,P]=+∞
最优解的 Steiner tree 即为 c[r,{u∗},{{u∗}}],下面来计算 c.
Leafnode: t 是 leaf node,那么 Xt={u∗}. 由于 u∗∈K,我们有 c[t,∅,∅]=+∞,c[t,{u∗},{{u∗}}]=0
Introducevertexnode: t 是 introduce vertex node,其孩子 t′ 有 Xt=Xt′∪{v},v∈/Xt′. 由于我们还没有引入任何与 v 相邻的边(考虑 introduce edge node),此时的 v 在 Gt 里是孤立的. 所以,对每一个集合 X⊆Xt 和 X 的划分 P={P1,P2,...,Pq},我们做以下操作:如果 v 是一个关键点,那么它必然是属于 X 的;如果 v 是属于 X 的,那有 {v} 就是 P 的一个连通分量. 如果上面的情况不能满足,那么我们让 c[t,X,P]=+∞. 否则:
Introduceedgenode: t 是一个引入了边 uv 的 introduce edge node,其孩子为 t′. 对任意的集合 X⊆Xt 和 X 的划分 P={P1,P2,...,Pq},我们考虑以下三种情况:如果 u∈/X 或者 v∈/X,那么我们就不能把 uv 包含进正在构建的树里(因为边的一个端点不与树相连),此时 c[t,X,P]=c[t′,X,P];同样的,如果 u 和 v 都在 X 里,但不在 P 的同一块里,结果是一样的; 如果 u 和 v 都在 X 里且都在 P 的同一个块里,此时可以选择是否添加边 uv. 如果选择不添加 uv,那么就直接 c[t,X,P]=c[t′,X,P];如果选择添加 uv,那么划分 P 里包含了 u 和 v 那个块就一定是通过合并两个小一点的块得到的(一个包含了 u 一个包含了 v). 于是有:
c[t,X,P]=min{minP′c[t′,X,P′]+1,c[t′,X,P]}
其中大括号里面那个 min,是我们考虑 X 的所有 u 和 v 不在同一个块里的划分 P′(否则添加 uv 将会出现环).
Forgetnode: t 是一个 forget node,其孩子 t′ 有 Xt=Xt′∖{v},v∈Xt′. 此时要分 v 是否在 X 和 P 对应的解决方案里. 如果在,那么 v 就该添加到 P 已有的块里;如果不在,那就取 t′ 里一样的 X 和 P. 具体见下面式子:
c[t,X,P]=min{minP′c[t′,X∪{v},P′],c[t′,X,P]}
其中大括号里面那个 min,是我们对所有 X∪{v} 的划分 P′ 所取的,注意这个 P′ 是通过把 v 添加到 P 里的一个块而得到的.
为了避免合并时出现环,我们将介绍一种结构:对于 X 的一个划分 P,令 GP 为一个森林,其中的连通分量恰好与 P 对应(即 P 里的每一块都有 GP 里的一个树和其有相同的点集). 如果 GP1 和 GP2 这两个森林合并后得到的森林里的连通分量恰好就是 P ,那么我们说 P 是对 P1 和 P2 的一个无环合并(acylicmerge). 于是有:
c[t,X,P]=minP1,P2c[t1,X,P1]+c[t2,X,P2]
这里的 min 是对所有能满足 P 是无环合并的的 P1, P2 对所取的.
下面来估计运算时间.
首先回忆一下,我们这里树分解里的每一个包最大大小为 k+2(宽度为 k+1 了),于是每一个节点的c 情况会至多有 2k+2 · (k+2)k+2=kO(k)(节点 t 最多 2∣Xt∣ 个子集 X⊆Xt,而 X 最多 |X|∣X∣ 个划分). 计算一个 c 需要最多考虑其他节点对的所有状态,需要时间 (kO(k))2=kO(k).
Theorem 7.8. 给定 n 个节点的图 G,K⊆V(G) 为给定的关键点集合,同时又给定宽度最多为 k 的树分解. 那么计算连接 K 的 Steinertree 的最小边数需要 kO(k) · n.
Algorithms similar to the dynamic programming of Theorem 7.8 can be used to solve many problems in time kO(k) · nO(1). Essentially, such a running time appears for problems with connectivity requirements, since then it is natural to keep in the dynamic programming state a partition of a subset of the bag. Since the number of such partitions is at most kO(k), this factor appears naturally in the running time.
The main challenge for most of the problems is to understand what information to store at nodes of the tree decomposition. Obtaining formulas for forget, introduce and join nodes can be a tedious task, but is usually straightforward once a precise definition of a state is established.