跳到主要内容

広島大学 先進理工系科学研究科 情報科学プログラム 2020年8月実施 専門科目II 問題2

Author

祭音Myyura

Description

有向グラフ G=(V,E,l)G = (V, E, l) を考える。 VV は頂点集合、EE は辺集合、l(e)l(e) は辺 ee の長さとする。 また、NvN_v を頂点 vv の隣接頂点集合とする。 この時、以下の Shortest(G,s)\textbf{Shortest}(G, s) は、GG 上のある頂点 ss を始点とし、頂点 ss から他の各頂点までの最短距離を求めるアルゴリズムである。

(1) Table 1 は、グラフ G1G_1 を入力とし、頂点 11 を始点とした場合の Shortest(G1,1)\textbf{Shortest}(G_1, 1) の実行の過程における、各頂点 vvd(v)d(v) の値を示したものである。Table 1 を完成させよ。

(2) GG のすべての辺の長さが非負である場合に、Shortest(G,s)\textbf{Shortest}(G, s) で得られる d(v)d(v) が、すべての頂点 vVv \in V について頂点 ss からの最短距離となることを証明せよ。

(3) GG に負の長さの辺が存在する場合には、Shortest(G,s)\textbf{Shortest}(G, s)ss からの最短距離を求められない場合があることを証明せよ。

(4) Shortest(G,s)\textbf{Shortest}(G, s) の最悪計算時間とその理由を述べよ。


Let G=(V,E,l)G = (V, E, l) be a directed graph, where VV is a set of nodes, EE is a set of edges, and l(e)l(e) is the non-negative length of edge ee. Let NvN_v be a set of adjacent nodes of node vv. The following algorithm Shortest(G,s)\textbf{Shortest}(G, s) computes the shortest distance from a node ss to each of the other nodes.

(1) Table 1 shows the value of d(v)d(v) for each vVv \in V in the process of execution of Shortest(G1,1)\textbf{Shortest}(G_1, 1), where the input graph is G1G_1 and the starting node is 11. Complete Table 1.

(2) Prove that d(v)d(v) for each vVv \in V stores the shortest distance from ss to vv when Shortest(G,s)\textbf{Shortest}(G, s) terminates.

(3) Prove that Shortest(G,s)\textbf{Shortest}(G, s) may not find the shortest distance if some of the edges take negative length.

(4) Derive the time complexity of Shortest(G,s)\textbf{Shortest}(G, s).

Kai

(1)

roundd(1)d(1)d(2)d(2)d(3)d(3)d(4)d(4)d(5)d(5)d(6)d(6)d(7)d(7)
10\infty\infty\infty\infty\infty\infty
2045\infty\infty\infty\infty
3045714\infty\infty
404571414\infty
504571310\infty
60457121012

(2)

Proof by contradiction:

Let δ(v)\delta(v) denote the length of a shortest path from ss to vv. Suppose that uu is the first vertex extracted from TT for which d(u)δ(u)d(u) \neq \delta(u).

Let sP1xyP2us \rightarrow P_1 \rightarrow x \rightarrow y \rightarrow P_2 \rightarrow u be a shortest path from ss to uu, where xx satifies d(x)=δ(x)d(x) = \delta(x) but yy does not. When xx is extracted from TT, since yy is adjacent to xx, d(y)d(y) will be updated

d(y)=d(x)+l(xy)δ(x)+l(xy)+l(yP2u)=δ(u)d(u)d(y) = d(x) + l(xy) \leq \delta(x) + l(xy) + l(y \rightarrow P_2 \rightarrow u) = \delta(u) \leq d(u)

Now both yy and uu are in TT when uu is chosen. Note that by assumption uu is the first vertex extracted from TT for which d(u)δ(u)d(u) \neq \delta(u), hence either d(y)=δ(y)d(y) = \delta(y) or yy is chosen after uu, which means that d(u)d(y)d(u) \leq d(y). But by assumption we have d(y)δ(y)d(y) \neq \delta(y), hence we have

d(u)d(y)d(u) \leq d(y)

Thus the two inequalities must be equalities,

d(y)=δ(u)=d(u)d(y) = \delta(u) = d(u)

a contradiction.

(3)

Shortest(G,A)\textbf{Shortest}(G, A) from AA will first develop BB, and will later fail to find ACBA \rightarrow C \rightarrow B.

(4)

If we stores the vertex set TT as a heap, and edges as an adjacent list, then finding uu of minimum d(u)d(u) takes O(logV)O(\log |V|).

Note that we need update d(v)d(v) of every vTNuv \in T \cap N_u, which can be done by inserting a "new vertex" vv of updated d(v)d(v) into heap TT, hence the size of TT is at most E|E|.

Therefore, the time complexity of Shortest(G,s)\textbf{Shortest}(G, s) is O(ElogV)O(|E|\log |V|).