広島大学 先進理工系科学研究科 情報科学プログラム 2020年8月実施 専門科目II 問題2
Author
祭音Myyura
Description
有向グラフ を考える。 は頂点集合、 は辺集合、 は辺 の長さとする。 また、 を頂点 の隣接頂点集合とする。 この時、以下の は、 上のある頂点 を始点とし、頂点 から他の各頂点までの最短距離を求めるアルゴリズムである。
(1) Table 1 は、グラフ を入力とし、頂点 を始点とした場合の の実行の過程における、各頂点 の の値を示したものである。Table 1 を完成させよ。
(2) のすべての辺の長さが非負である場合に、 で得られる が、すべての頂点 について頂点 からの最短距離となることを証明せよ。
(3) に負の長さの辺が存在する場合には、 は からの最短距離を求められない場合があることを証明せよ。
(4) の最悪計算時間とその理由を述べよ。
Let be a directed graph, where is a set of nodes, is a set of edges, and is the non-negative length of edge . Let be a set of adjacent nodes of node . The following algorithm computes the shortest distance from a node to each of the other nodes.
(1) Table 1 shows the value of for each in the process of execution of , where the input graph is and the starting node is . Complete Table 1.
(2) Prove that for each stores the shortest distance from to when terminates.
(3) Prove that may not find the shortest distance if some of the edges take negative length.
(4) Derive the time complexity of .
题目描述
考虑有向图 ,其中 为顶点集、 为边集、 为边 的长度, 表示顶点 的邻接顶点集。图中给出的算法 以 为起点,计算从 到其他各顶点的最短距离。
- 表 1 记录以图 为输入、顶点 为起点执行 时,各轮中每个顶点 的 值;补全该表。
- 当 的所有边长均非负时,证明算法结束后,对每个 , 都等于从 到 的最短距离。
- 证明当 中存在负长度边时, 可能无法求出从 出发的最短距离。
- 给出 的最坏运行时间并说明理由。
算法、图 与待补全的表 1 均见题中图示。
Kai
(1)
| round | |||||||
|---|---|---|---|---|---|---|---|
| 1 | 0 | ||||||
| 2 | 0 | 4 | 5 | ||||
| 3 | 0 | 4 | 5 | 7 | 14 | ||
| 4 | 0 | 4 | 5 | 7 | 14 | 14 | |
| 5 | 0 | 4 | 5 | 7 | 13 | 10 | |
| 6 | 0 | 4 | 5 | 7 | 12 | 10 | 12 |
| 7 | 0 | 4 | 5 | 7 | 12 | 10 | 12 |
| 8 | 0 | 4 | 5 | 7 | 12 | 10 | 12 |
(2)
Let be the shortest distance from to , with for an unreachable vertex. Every finite label is the length of an actual path, so .
We prove by induction that a vertex has its correct distance when it is extracted from . The first vertex is , with distance . Suppose the assertion holds for all previously extracted vertices, and let be the next one.
If is reachable, choose a shortest path from to . Let be its first vertex still in and its predecessor. Then has already been extracted with , and its relaxation gives . Nonnegative edge lengths imply , while the choice of gives . Hence
so . If is unreachable, no relaxation can give it a finite label, and . This completes the induction.
(3)
Take the directed graph with exactly three edges:
Starting from , the algorithm extracts with label before with label . When is extracted, is no longer in , so the displayed algorithm does not relax . It returns , although the shortest path has length .
(4)
If the displayed find operation scans directly, its total cost is , while all relaxations cost . Thus the displayed implementation takes
for a simple graph.
With adjacency lists and a binary min-heap, the algorithm performs extract-min operations and at most decrease-key operations. Therefore its worst-case running time is
For a connected graph, this is .