跳到主要内容

東京大学 情報理工学系研究科 コンピュータ科学専攻 2023年8月実施 専門科目 問題3

Author

zephyr, 祭音Myyura

Description

Let G=(V,E)G = (V, E) be an undirected graph with no self-loops (edges joining the same vertex) nor multi-edges (two or more edges joining the same two vertices), with V=n|V| = n, E=m|E| = m. If there is a vertex vv in a connected graph GG such that after deleting vv, the resulting graph is not connected, we call vv a cut vertex of GG.

Answer the following questions:

(1) Describe an algorithm to check whether or not GG is connected. Estimate the time complexity of the algorithm.

(2) Describe a O(m)O(m) time algorithm to find a spanning tree TT, given a connected graph GG.

(3) Let TT be a spanning tree of a connected graph GG, and assume that vv is a non-leaf node of TT (i.e., the degree of vv in TT is at least two) and that vv is not a cut vertex of GG. Let ee be an edge of TT that is incident with vv. Prove that one can obtain another spanning tree of GG from TT by replacing ee with another edge fef \neq e of GG.

(4) Describe a o(mn)o(mn) time algorithm, given a connected graph GG, to find all cut vertices of GG.


G=(V,E)G = (V, E) 为一个无向图,该图没有自环(连接到同一顶点的边)也没有重边(连接同一对顶点的两个或更多边),且 V=n|V| = nE=m|E| = m。如果在一个连通图 GG 中有一个顶点 vv,使得删除 vv 后所得的图不再连通,我们称 vvGG 的割点。

回答以下问题:

(1) 描述一个算法来检查 GG 是否连通。估计该算法的时间复杂度。

(2) 描述一个 O(m)O(m) 时间的算法,给定一个连通图 GG,找到一棵生成树 TT

(3) 设 TT 为连通图 GG 的一棵生成树,并假设 vvTT 的一个非叶节点(即 vvTT 中的度数至少为二),并且 vv 不是 GG 的割点。令 eeTT 中与 vv 相邻的一条边。证明通过用 GG 的另一条边 fef \neq e 替换 ee,可以得到 GG 的另一棵生成树。

(4) 描述一个 o(mn)o(mn) 时间的算法,给定一个连通图 GG,找到 GG 的所有割点。

题目描述

G=(V,E)G=(V,E) 为无自环、无重边的无向图, V=n|V|=nE=m|E|=m。若连通图 GG 中的顶点 vv 被删除后所得图不连通,则称 vvGG 的割点。回答下列问题。

(1)描述判断 GG 是否连通的算法,并估计时间复杂度。

(2)给定连通图 GG,描述一个 O(m)O(m) 时间算法求其生成树 TT

(3)设 TT 是连通图 GG 的生成树,vvTT 的非叶结点(在 TT 中度至少为二),且 vv 不是 GG 的割点。令 eeTT 中一条与 vv 相接的边。证明存在 GG 中另一条边 fef\ne e,用 ff 替换 ee 后仍得到 GG 的一棵生成树。

(4)给出一个耗时为 o(mn)o(mn) 的算法,输入连通图 GG,找出其所有割点。

Kai

(1)

Algorithm

To check whether the graph G=(V,E)G = (V, E) is connected, you can perform a Depth-First Search (DFS) or Breadth-First Search (BFS) starting from any vertex vVv \in V. The algorithm proceeds as follows:

  1. Start from an arbitrary vertex v0v_0 and perform DFS or BFS.
  2. Mark all visited vertices during the search.
  3. After the search is complete, check if all vertices have been visited.

If all vertices are visited, then the graph is connected; otherwise, it is not.

Time Complexity

  • The time complexity of both DFS and BFS is O(n+m)O(n + m), where n=Vn = |V| and m=Em = |E|. This is because, in the worst case, you will visit every vertex and every edge exactly once.

(2)

Algorithm

To find a spanning tree TT for a connected graph GG, you can use a Depth-First Search (DFS) or Breadth-First Search (BFS):

  1. Start from an arbitrary vertex v0v_0 and initialize TT as an empty set of edges.
  2. Perform DFS or BFS, adding (x,y)(x,y) to TT only when it first discovers the unvisited vertex yy from xx.
  3. The resulting set of edges TT forms a spanning tree.

Time Complexity

  • With adjacency lists the time is O(n+m)=O(m)O(n+m)=O(m), since a connected graph has mn1m\ge n-1.

(3)

Proof

Write e={v,u}e=\{v,u\}, and let CC be the component of TeT-e containing uu. Since vv is not a leaf, the other component contains a vertex different from vv. As GvG-v is connected, a path in GvG-v joins these two components. Some edge ff of this path crosses the cut (C,VC)(C,V\setminus C); moreover fef\ne e. Hence

(Te)+f(T-e)+f

is connected and has n1n-1 edges, so it is a spanning tree.

(4)

Algorithm

To find all cut vertices of GG efficiently, we can use a Depth-First Search (DFS) based algorithm, known as Tarjan's algorithm:

  1. Perform a DFS traversal of GG, numbering the vertices in the order they are visited.
  2. For each vertex vv, maintain two values:
    • DFS number: The order in which the vertex was visited.
    • Low number: The smallest DFS number reachable from the subtree of vv using at most one back edge.
  3. A vertex vv is a cut vertex if:
    • It is the root of the DFS tree and has more than one child.
    • It is not the root, and it has a child uu with low(u)dfs(v)\operatorname{low}(u)\ge\operatorname{dfs}(v).

Time Complexity

  • The time complexity is O(n+m)O(n+m), which is o(mn)o(mn) for connected graphs as nn\to\infty.

Knowledge

DFS 图论 连通性 生成树 割点 切点

解题技巧和信息

  1. 图的连通性检查: DFS 和 BFS 是检查图的连通性的基本工具。
  2. 生成树构造: DFS 或 BFS 都可以用来构造图的生成树,时间复杂度为 O(m)O(m)
  3. 割点的寻找: Tarjan 算法是寻找割点的经典算法,其时间复杂度为 O(n+m)O(n + m),适合大规模图的处理。

重点词汇

  • Cut vertex: 割点
  • Spanning tree: 生成树
  • Depth-First Search (DFS): 深度优先搜索
  • Connected graph: 连通图

参考资料

  1. Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. "Introduction to Algorithms." MIT Press, Chapter 22, "Elementary Graph Algorithms".
  2. Robert Tarjan, "Depth-First Search and Linear Graph Algorithms", SIAM Journal on Computing, 1972.