京都大学 情報学研究科 知能情報学専攻 2021年2月実施 基礎科目 F2-2
Author
祭音Myyura (co-authored with GPT 5.6 SOL)
Description
Let be a simple undirected graph. Each vertex has a positive integer weight . A set is independent if for every pair . Its weight is
An independent set of maximum weight is called a maximum independent set, and its weight is denoted by .
(1)
Give a maximum independent set and 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
(2)
From this point on, consider rooted trees only. For a vertex , let be the subtree rooted at , and define
For the following tree , give . The root is , and the numbers in brackets are vertex weights.
r1[2]
/ | \
v1[2] v2[3] [1]
/ \
[3] [2]
|
[1]
(3)
Algorithm 1 computes for a tree rooted at . Fill the blanks (a)--(f). If necessary, use for the set of children of .
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 is used to determine the order of vertices processed at line 3. Which ordering is appropriate: preorder, inorder, or postorder? Give reasons.
(5)
Let be the number of vertices in . Give the time complexity of Algorithm 1 with reasons.
题目描述
设简单无向图 的每个顶点 有正整数权重 。 独立集 的权重为 ,最大权独立集的权重记作 。
- 对题图 ,给出一个最大权独立集及 。
- 对根树定义: 为必须选 时子树 的最大独立集权重, 为不选 时的最大权重,。 求题图 中 各自的 。
- 补全自底向上计算 的算法空栏 (a)--(f)。
- 为保证处理顶点时其子结点均已处理,应采用前序、中序还是后序遍历?说明理由。
- 设输入树有 个顶点,求算法的时间复杂度并说明理由。
Kai
(1)
The set
is independent, and its weight is
For completeness, conditioning on whether vertices and are selected gives the following best possible weights:
| best weight | ||
|---|---|---|
| no | no | |
| no | yes | |
| yes | no | |
| yes | yes |
Therefore,
(2)
The vertex is a leaf of weight , so
For the weight- child of , whose only child has weight , the three values are . For the weight- leaf child, they are . Consequently,
Thus
(3)
For a leaf, selecting it gives its weight and excluding it gives zero. For a non-leaf, selecting forces every child to be excluded, while excluding allows the optimal choice in every child subtree. Hence the blanks are
(4)
The appropriate ordering is
Postorder visits every child before its parent, so all values needed to compute are already available when 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 takes time, and
Therefore the total running time is