← 回題庫

卷別

資料結構與演算法

選擇

國立臺灣大學 2025 · 考試 · 第 15 題

考科演算法

(5 points) In this problem we use the following notations. For any binary tree TT, we define T.xT.x to be its root node, T.lT.l (resp. T.rT.r) to be the left (resp. right) child of T.xT.x, and T.LT.L (resp. T.RT.R) to be the left (resp. right) subtree of T.xT.x. For any vertex xx on a binary tree, we define x.lx.l, x.Lx.L, x.rx.r, and x.Rx.R similarly. These values are defined as ⊥\bot (empty) if they do not exist. The set of leaves of TT are denoted as Leaf(T)\mathrm{Leaf}(T). For any statement PP we define ⟦P⟧\llbracket P \rrbracket to be 11 if PP is true and 00 if PP is false.

Let TT be a binary tree of nn nodes. Each node vv on TT has a weight w(v)w(v) and a color c(v)c(v). We want to make the tree colorful in the sense that every non-root tree node has a color different from its parent. To do so, some re-coloring to the tree nodes are necessary, and we would like to minimize the total weights of the tree nodes that are re-colored. Notice that there are infinitely many colors available so once a node is re-colored it gets a unique color. Let f(T)f(T) be the answer. Suppose that both T.LT.L and T.RT.R are non-empty. What is the correct recursive formulations for f(T)f(T)? Select all choice(s) that apply.

  • (A)
    Let T′⊆TT' \subseteq T be the (partial) binary tree consisting of all tree node vv who has the same color as the tree root T.xT.x and all vv's ancestors have the same color c(T.x)c(T.x) too. Then, f(T)=g(T′)+∑a∈Leaf(T′)(f(a.L)+f(a.R))f(T) = g(T') + \sum_{a \in \mathrm{Leaf}(T')}(f(a.L) + f(a.R)), here g(T′)g(T') is the weight of the maximum weighted independent set on T′T'.
  • (B)
    With the same notion T′T' defined above, f(T)=h(T′)+∑a∈Leaf(T′)(f(a.L)+f(a.R))f(T) = h(T') + \sum_{a \in \mathrm{Leaf}(T')}(f(a.L) + f(a.R)), here h(T′)h(T') is the weight of the minimum weighted vertex cover on T′T'.
  • (C)
    With the same notion T′T' defined above, f(T)=h(T′)+∑a∈Leaf(T′)(f(a.L)+f(a.R))f(T) = h(T') + \sum_{a \in \mathrm{Leaf}(T')}(f(a.L) + f(a.R)), here h(T′)h(T') is the weight of the minimum weighted dominating set on T′T'.
  • (D)
    f(T)=min⁡{ f(T.L)+f(T.R)+w(T.x), ⟦c(T.l)==c(T.x)⟧⋅(w(T.l)+f(T.L))+⟦c(T.l)≠c(T.x)⟧⋅f(T.L)+⟦c(T.r)==c(T.x)⟧⋅(w(T.r)+f(T.R))+⟦c(T.r)≠c(T.x)⟧⋅f(T.R) }f(T) = \min\{\,f(T.L) + f(T.R) + w(T.x),\ \llbracket c(T.l){=}{=}c(T.x) \rrbracket \cdot (w(T.l) + f(T.L)) + \llbracket c(T.l) \neq c(T.x) \rrbracket \cdot f(T.L) + \llbracket c(T.r){=}{=}c(T.x) \rrbracket \cdot (w(T.r) + f(T.R)) + \llbracket c(T.r) \neq c(T.x) \rrbracket \cdot f(T.R)\,\}.
  • (E)
    None of the above choices apply.

標準解析

已標記