跳到主要内容

東京大学 情報理工学系研究科 創造情報学専攻 2009年8月実施 筆記試験 第1問

Author

itsuitsuki

Description

Given a directed graph G=(V,E)G = (V, E), we would like to find all-pairs shortest path lengths which are the all shortest path lengths between every pair of vertices, where the size of the set V,V=nV, |V| = n. Let euve_{uv} denote a directed edge from a vertex uu to a vertex vv, and δuv\delta_{uv} denote the length of the edge euve_{uv}. The graph GG may have a negative length edge but does not have any negative length cycle. The length of the edge from the vertex uu to the same vertex u,δuu=0u, \delta_{uu} = 0, and when there exists no edge from the vertex uu to the vertex vv, δuv=\delta_{uv} = \infty.

Algorithm 1 on the next page outputs the single-source shortest path lengths. Let sVs \in V be a single source vertex, the shortest path length from the vertex ss to a vertex vVv \in V is stored in d(v)d(v). Algorithm 2 outputs the all-pairs shortest path lengths table DD, where the length of the shortest path from a vertex uu to a vertex vv is stored in D(u,v)D(u, v). Each algorithm uses d(k)d^{(k)} and D(k)(k=0,1,)D^{(k)} (k = 0, 1, \dots) to store interim results, respectively. Answer the following questions.

(1) Apply Algorithm 1 to the graph G1=(V1,E1)G_1 = (V_1, E_1) in Figure 1 to obtain the shortest path length from a single-source vertex v0v_0. Table 1 shows d(0)d^{(0)} in Algorithm 1. Show the single-source path length d(1),d(2),d(3)d^{(1)}, d^{(2)}, d^{(3)}, and d(4)d^{(4)} from the single-source vertex v0v_0.

(2) Apply Algorithm 2 to the graph G1=(V1,E1)G_1 = (V_1, E_1) in Figure 1 to obtain the all-pairs shortest path lengths. Table 2 shows D(0)D^{(0)} in Algorithm 2. Show the selected vertex wV1w \in V_1 in the Main Loop and the corresponding table D(1),D(2),D(3),D(4)D^{(1)}, D^{(2)}, D^{(3)}, D^{(4)}, and D(5)D^{(5)}.

(3) To obtain all-pairs shortest path lengths, consider Algorithm 1-ALL which applies Algorithm 1 for all vertices in VV as a single-source vertex. Compare Algorithm 1-ALL and Algorithm 2.

Table 1: d(0)d^{(0)} in Algorithm 1

destination
v0v_00
v1v_1\infty
v2v_2\infty
v3v_3\infty
v4v_4\infty

Table 2: D(0)D^{(0)} in Algorithm 2

source\destinationv0v_0v1v_1v2v_2v3v_3v4v_4
v0v_001\infty59
v1v_1\infty013\infty
v2v_2\infty\infty0-1\infty
v3v_3\infty1\infty01
v4v_41\infty\infty\infty0
本页目录