京都大学 情報学研究科 数理工学専攻 2016年8月実施 グラフ理論
Author
祭音Myyura
Description
Let be a simple strongly connected directed graph. Let be a network obtained by assigning a nonnegative real weight to each arc . An arc from vertex u to vertex v is denoted by , and its weight is also denoted by . Define as the minimum total weight of a simple directed path from to in .
Answer the following questions.
(i) Let and . Among all arcs going from to , choose an arc minimizing
Prove that
(ii) Show that Dijkstra’s algorithm from a starting vertex can be implemented in time on .
(iii) If one arc with negative weight is added to , the values output by Dijkstra’s algorithm may fail to be correct shortest distances. Construct a concrete example with
and explain how Dijkstra’s algorithm fails.
题目描述
设 是简单强连通有向图,网络 由给每条弧 赋予非负实权 得到。用 表示从顶点 指向 的弧,其权重也记作 ; 定义为 中从 到 的简单有向路的最小总权重。回答:
- 设 、。在所有从 指向 的弧 中,选取使
最小的 。证明
- 证明以任意 为起点的 Dijkstra 算法可在 上实现为 时间。
- 若在 中加入一条负权弧,Dijkstra 算法的输出可能不再是正确的最短距离。构造一个满足 的具体例子,并说明算法如何失效。
考点
- Dijkstra 算法的正确性:利用非负边权证明跨越已确定顶点集合的最小候选弧能确定新顶点的最短距离。
- 优先队列复杂度分析:用堆维护暂定距离,说明算法达到 。
- 负权边反例:构造极小有向网络,展示顶点被永久确定后仍可能经负权弧得到更短路径。
Kai
(i)
Take a shortest path from to , and then append the arc . If this walk repeats vertices, we may delete cycles. Since all edge weights are nonnegative, deleting cycles cannot increase the total weight. Hence there is a simple path from to of weight at most
i.e.,
Now we prove the reverse inequality.
Let $$Psv^s \in Sv^ \in V - SPSV−S$ at least once.
Let be the first arc of that goes from to . Thus and . The part of from to has weight at least . Also, all edge weights after are nonnegative. Hence
By the choice of ,
Hence,
Combining the two inequalities, we get
(ii)
Use an adjacency-list representation and a binary heap priority queue supporting Extract-Min and Decrease-Key, the pseudocode of Dijkstra algorithm is given as follows:
Dijkstra(G, w, s):
for each vertex v in V:
d[v] = infinity
parent[v] = NIL
d[s] = 0
S = empty set
Q = priority queue containing all vertices v, keyed by d[v]
while Q is not empty:
u = Extract-Min(Q)
add u to S
// At this moment, d[u] is fixed.
// It will never be changed again.
for each outgoing arc (u, v) in Adj[u]:
if v is not in S:
if d[v] > d[u] + w(u, v):
d[v] = d[u] + w(u, v)
parent[v] = u
Decrease-Key(Q, v, d[v])
return d, parent
For the time complexity
- Each vertex is extracted from the priority queue once:
- Each arc is relaxed once, and each successful relaxation causes a priority queue update:
As the directed graph is strongly connected, we have when .
Thus the total running time is
(iii)
The true shortest distance from to is using the path .
Now run Dijkstra’s algorithm from .
Initially,
After processing ,
Dijkstra chooses a next because . It fixes , but the true distance is .
Therefore Dijkstra’s algorithm fails when a negative-weight edge is allowed.