東京大学 新領域創成科学研究科 メディカル情報生命専攻 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 - 
(B) 
- (C) Given 
我们将从顶点 
(1) 让我们考虑下图所示的有向图。
- (A) 显示邻接矩阵。
- (B) 显示一个矩阵 
 
(2) 假设我们有一个简单的有向图 
- (A) 设 - (B) 
- (C) 给定 
Kai
(1)
(A)
The adjacency matrix 
(B)
The matrix 
- 
Initialize 
 
- 
Update 
The final 
(2)
(A)
The matrix 
(B)
To find 
(C)
The Floyd-Warshall algorithm is suitable for computing all-pair shortest distances:
- Initialize - Update 
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 章 最短路径算法