跳到主要内容

東京大学 新領域創成科学研究科 メディカル情報生命専攻 2022年8月実施 問題9

Author

zephyr

Description

Let G=(V,E)G = (V, E) be a directed acyclic graph such that VV is the set of integers from 11 to nn (n3)(n \geq 3). We will consider the following sets of edges for EE.

E1={(1,i),(i,n)i=2,,n1}E_1 = \{(1, i), (i, n) \mid i = 2, \ldots, n-1\}
E2={(i,i+1)i=1,,n1}{(i,i+2)i=1,,n2}E_2 = \{(i, i+1) \mid i = 1, \ldots, n-1\} \cup \{(i, i+2) \mid i = 1, \ldots, n-2\}

(1) Consider a bijective function ff from VV to VV such that f(u)<f(v)f(u) < f(v) for any (u,v)E(u, v) \in E. For each of E1E_1 and E2E_2, answer the number of all different bijective functions and the rationale.

(2) For each of E1E_1 and E2E_2, answer the number of all different paths from 11 to nn (or a recurrence for computing the number), and the rationale.

(3) For any directed acyclic graph G=(V,E)G = (V, E), design an algorithm that calculates the number of paths from ss to tt in O(V+E)O(|V| + |E|) time for any s,tVs, t \in V, and explain the rationale.

Kai

(1) Bijective Functions

Bijective Function Explanation

A bijective function f:VVf: V \rightarrow V is a function that is both injective (one-to-one) and surjective (onto). This means every element in VV maps to a unique element in VV, and every element in VV is mapped to by exactly one element in VV. For the given problem, we are interested in bijective functions that also respect the condition f(u)<f(v)f(u) < f(v) for any edge (u,v)E(u, v) \in E.

For E1E_1

  • Structure: The graph GG with edges E1E_1 has two types of edges: from vertex 1 to every other vertex i{2,,n1}i \in \{2, \ldots, n-1\}, and from every vertex i{2,,n1}i \in \{2, \ldots, n-1\} to vertex nn. Thus, f(1)f(1) must be the smallest and f(n)f(n) must be the largest.

  • Ordering: The remaining values {f(2),,f(n1)}\{f(2), \ldots, f(n-1)\} must be placed in increasing order between f(1)f(1) and f(n)f(n).

  • Number of bijective functions: Given that f(1)f(1) and f(n)f(n) are fixed as the smallest and largest respectively, the remaining n2n-2 vertices can be permuted freely.

(n2)! (n-2)!

For E2E_2

  • Structure: The graph GG with edges E2E_2 has edges from each vertex ii to i+1i+1 and i+2i+2.

  • Ordering: For ff to satisfy f(u)<f(v)f(u) < f(v) for all (u,v)E2(u, v) \in E_2, f(i)f(i) must be in ascending order for all ii.

  • Number of bijective functions: There is only one valid permutation: the natural ordering f(i)=if(i) = i.

11

(2) Number of Paths from 11 to nn

For E1E_1

  • Path Analysis: From 11 to nn, the paths must pass through an intermediate vertex ii.

  • Paths: Each vertex ii in {2,,n1}\{2, \ldots, n-1\} provides a unique path 1in1 \rightarrow i \rightarrow n.

Number of paths=n2 \text{Number of paths} = n-2

For E2E_2

  • Path Analysis: From 11 to nn, paths can be analyzed using dynamic programming:

    Define P(k)P(k) as the number of paths from 11 to kk.

P(k)=P(k1)+P(k2) P(k) = P(k-1) + P(k-2)
  • Base cases: P(1)=1P(1) = 1 (direct path from 1 to 1)

  • For P(2)P(2), there is also a direct path, so P(2)=1P(2) = 1.

  • Recurrence relation: Compute the number of paths to each vertex until P(n)P(n).

(3) Algorithm for Number of Paths in a DAG

Algorithm

  • Initialize an array PP of size V|V| to store the number of paths to each vertex.
  • Initialize P(s)=1P(s) = 1 for the starting vertex ss.
  • Traverse the vertices in topological order, and update the number of paths to each vertex based on the incoming edges.
    • For each vertex vv, iterate over its incoming neighbors uu and update P(v)+=P(u)P(v) += P(u).
  • Once all vertices are processed, the number of paths to the destination vertex tt will be stored in P(t)P(t).

Time Complexity

  • The topological sort can be done in O(V+E)O(|V| + |E|) time.
  • Updating the number of paths for each vertex takes O(E)O(|E|) time.
  • Thus, the overall time complexity is O(V+E)O(|V| + |E|).

Knowledge

图论 有向无环图 拓扑排序 动态规划 双射函数

难点解题思路

在 Part 1 中,需要理解图的结构及其对函数 ff 的约束。在 Part 2 中,关键在于找出从起点到终点的所有可能路径数目,并用动态规划求解。在 Part 3 中,难点在于设计有效算法,通过拓扑排序和动态规划计算从起点到终点的路径数目。

解题技巧和信息

对于有向无环图 (DAG) 相关的问题,拓扑排序和动态规划是常用的解题技巧。在这个问题中,我们需要理解图的结构,找出有效的算法来计算从起点到终点的路径数目。

重点词汇

  • directed acyclic graph (DAG) 有向无环图
  • topological order 拓扑排序
  • dynamic programming 动态规划
  • bijective function 双射函数
  • recurrence 递推关系

参考资料

  1. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (3rd ed.). MIT Press. Chap. 22 (Elementary Graph Algorithms), Chap. 24 (Single-Source Shortest Paths).