京都大学 情報学研究科 数理工学専攻 2016年8月実施 グラフ理論
Author
祭音Myyura
Description
Let
Answer the following questions.
(i) Let
Prove that
(ii) Show that Dijkstra’s algorithm from a starting vertex
(iii) If one arc with negative weight is added to
and explain how Dijkstra’s algorithm fails.
Kai
(i)
Take a shortest path from
i.e.,
Now we prove the reverse inequality.
Let $$P
Let
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
Thus the total running time is
(iii)
The true shortest distance from
Now run Dijkstra’s algorithm from
Initially,
After processing
Dijkstra chooses a next because
Therefore Dijkstra’s algorithm fails when a negative-weight edge is allowed.