東京大学 新領域創成科学研究科 メディカル情報生命専攻 2016年8月実施 問題10
Author
Description
We define the shortest distance from a vertex
(1) Let us consider the directed graph shown below.
- (A) Show the adjacency matrix.
- (B) Show a matrix
, whose element is the shortest distance from a vertex to a vertex .

(2) Suppose we are given a simple directed graph
-
(A) Let
. Let be the set of edges in that start from and end at a vertex in . Let be the shortest distance from a vertex to a vertex on a directed graph , and let . Express in terms of . -
(B)
can be computed from as follows. Fill in the two blanks.
- (C) Given
, show an algorithm to compute the all-pair shortest distances, and find its time complexity with regard to .
我们将从顶点
(1) 让我们考虑下图所示的有向图。
- (A) 显示邻接矩阵。
- (B) 显示一个矩阵
,其元素 是从顶点 到顶点 的最短距离。

(2) 假设我们有一个简单的有向图
- (A) 设
。设 为从顶点 中的顶点出发并结束于顶点的边集。设 为有向图 上从顶点 到顶点 的最短距离,并设 。用 表示 。 - (B)
可以从 计算如下。填写两个空格。
- (C) 给定
,展示一个算法来计算所有对的最短距离,并找到其关于 的时间复杂度。
Kai
(1)
(A)
The adjacency matrix
(B)
The matrix
-
Initialize
with: if if there is an edge from to otherwise
-
Update
using the Floyd-Warshall algorithm:
The final
(2)
(A)
The matrix
(B)
To find
(C)
The Floyd-Warshall algorithm is suitable for computing all-pair shortest distances:
- Initialize
where is 0 if , 1 if there is an edge , and otherwise. - Update
using: for all vertices from 1 to .
Algorithm:
function FloydWarshall(V, E):
let D be a |V| x |V| matrix of minimum distances
for each vertex v in V:
D[v][v] = 0
for each edge (u, v) in E:
D[u][v] = 1
for each k from 1 to |V|:
for each i from 1 to |V|:
for each j from 1 to |V|:
D[i][j] = min(D[i][j], D[i][k] + D[k][j])
return D
Time Complexity:
The time complexity of the Floyd-Warshall algorithm is
Knowledge
最短路径 Floyd-Warshall算法 图论
重点词汇
- adjacency matrix 邻接矩阵
- shortest distance 最短距离
- edge 边
- vertex 顶点
参考资料
- 《算法导论》 第 25 章 最短路径算法