跳到主要内容

京都大学 情報学研究科 知能情報学専攻 2021年2月実施 基礎科目 F2-2

Author

祭音Myyura (co-authored with GPT 5.6 SOL)

Description

Let G=(V,E)G=(V,E) be a simple undirected graph. Each vertex vVv\in V has a positive integer weight w(v)w(v). A set SVS\subseteq V is independent if (u,v)E(u,v)\notin E for every pair u,vSu,v\in S. Its weight is

w(S)=vSw(v).w(S)=\sum_{v\in S}w(v).

An independent set of maximum weight is called a maximum independent set, and its weight is denoted by IN(G)\operatorname{IN}(G).

(1)

Give a maximum independent set and IN(G1)\operatorname{IN}(G_1) for the following graph. The integer beside each vertex name is its weight.

a(2) ----- c(1) ----- e(1)       g(2)
| \ | | \ |
| \ | | \ |
b(2) ----- d(3) ----- f(2) ----- h(3)

Thus

E(G1)={(a,b),(a,c),(a,d),(b,d),(c,d),(c,e),(d,f),(e,f),(e,h),(f,h),(g,h)}.\begin{aligned} E(G_1)=\{& (a,b),(a,c),(a,d),(b,d),(c,d),(c,e),\\ &(d,f),(e,f),(e,h),(f,h),(g,h)\}. \end{aligned}

(2)

From this point on, consider rooted trees only. For a vertex vv, let T(v)T(v) be the subtree rooted at vv, and define

X(v)=max{w(S)S is independent in T(v), vS},Y(v)=max{w(S)S is independent in T(v), vS},Z(v)=IN(T(v)).\begin{aligned} X(v)&=\max\{w(S)\mid S\text{ is independent in }T(v),\ v\in S\},\\ Y(v)&=\max\{w(S)\mid S\text{ is independent in }T(v),\ v\notin S\},\\ Z(v)&=\operatorname{IN}(T(v)). \end{aligned}

For the following tree T1T_1, give X(v1),Y(v1),Z(v1),X(v2),Y(v2),Z(v2)X(v_1),Y(v_1),Z(v_1),X(v_2),Y(v_2),Z(v_2). The root is r1r_1, and the numbers in brackets are vertex weights.

                 r1[2]
/ | \
v1[2] v2[3] [1]
/ \
[3] [2]
|
[1]

(3)

Algorithm 1 computes IN(T)\operatorname{IN}(T) for a tree rooted at rr. Fill the blanks (a)--(f). If necessary, use C(v)C(v) for the set of children of vv.

Algorithm 1
Input: A tree T rooted at r.
Output: IN(T).

1: Let all vertices be unmarked.
2: while there is an unmarked vertex do
3: Let v be an unmarked vertex having no unmarked child.
4: Mark v.
5: if v is a leaf then
6: X(v) := (a); Y(v) := (b); Z(v) := (c).
7: else
8: X(v) := (d); Y(v) := (e); Z(v) := (c).
9: end if
10: end while
11: Output (f).

(4)

Suppose depth-first search from rr is used to determine the order of vertices processed at line 3. Which ordering is appropriate: preorder, inorder, or postorder? Give reasons.

(5)

Let nn be the number of vertices in TT. Give the time complexity of Algorithm 1 with reasons.

题目描述

设简单无向图 G=(V,E)G=(V,E) 的每个顶点 vv 有正整数权重 w(v)w(v)。 独立集 SS 的权重为 w(S)=vSw(v)w(S)=\sum_{v\in S}w(v),最大权独立集的权重记作 IN(G)\operatorname{IN}(G)

  1. 对题图 G1G_1,给出一个最大权独立集及 IN(G1)\operatorname{IN}(G_1)
  2. 对根树定义:X(v)X(v) 为必须选 vv 时子树 T(v)T(v) 的最大独立集权重, Y(v)Y(v) 为不选 vv 时的最大权重,Z(v)=IN(T(v))Z(v)=\operatorname{IN}(T(v))。 求题图 T1T_1v1,v2v_1,v_2 各自的 X,Y,ZX,Y,Z
  3. 补全自底向上计算 IN(T)\operatorname{IN}(T) 的算法空栏 (a)--(f)。
  4. 为保证处理顶点时其子结点均已处理,应采用前序、中序还是后序遍历?说明理由。
  5. 设输入树有 nn 个顶点,求算法的时间复杂度并说明理由。

Kai

(1)

The set

S={b,c,f,g}\boxed{S=\{b,c,f,g\}}

is independent, and its weight is

w(S)=2+1+2+2=7.w(S)=2+1+2+2=7.

For completeness, conditioning on whether vertices dd and hh are selected gives the following best possible weights:

dSd\in ShSh\in Sbest weight
nono77
noyes66
yesno66
yesyes66

Therefore,

IN(G1)=7.\boxed{\operatorname{IN}(G_1)=7}.

(2)

The vertex v1v_1 is a leaf of weight 22, so

X(v1)=2,Y(v1)=0,Z(v1)=2.\boxed{X(v_1)=2,\qquad Y(v_1)=0,\qquad Z(v_1)=2}.

For the weight-33 child of v2v_2, whose only child has weight 11, the three values are (3,1,3)(3,1,3). For the weight-22 leaf child, they are (2,0,2)(2,0,2). Consequently,

X(v2)=3+1+0=4,Y(v2)=3+2=5,Z(v2)=max{4,5}=5.\begin{aligned} X(v_2)&=3+1+0=4,\\ Y(v_2)&=3+2=5,\\ Z(v_2)&=\max\{4,5\}=5. \end{aligned}

Thus

X(v2)=4,Y(v2)=5,Z(v2)=5.\boxed{X(v_2)=4,\qquad Y(v_2)=5,\qquad Z(v_2)=5}.

(3)

For a leaf, selecting it gives its weight and excluding it gives zero. For a non-leaf, selecting vv forces every child to be excluded, while excluding vv allows the optimal choice in every child subtree. Hence the blanks are

blankexpression(a)w(v)(b)0(c)max{X(v),Y(v)}(d)w(v)+uC(v)Y(u)(e)uC(v)Z(u)(f)Z(r)\begin{array}{c|l} \text{blank}&\text{expression}\\ \hline (a)&w(v)\\ (b)&0\\ (c)&\max\{X(v),Y(v)\}\\ (d)&w(v)+\displaystyle\sum_{u\in C(v)}Y(u)\\ (e)&\displaystyle\sum_{u\in C(v)}Z(u)\\ (f)&Z(r) \end{array}

(4)

The appropriate ordering is

postorder.\boxed{\text{postorder}}.

Postorder visits every child before its parent, so all values needed to compute X(v),Y(v),Z(v)X(v),Y(v),Z(v) are already available when vv is processed. Preorder does the opposite, and inorder does not guarantee this property.

(5)

Using the postorder schedule, every vertex is processed once. Computing the values at vv takes O(C(v))O(|C(v)|) time, and

vVC(v)=n1.\sum_{v\in V}|C(v)|=n-1.

Therefore the total running time is

Θ(n).\boxed{\Theta(n)}.