Dijkstra 算法的准确性如何?

How accurate is Dijkstra Algorithm?

Dijkstra算法有必要总是找到两个veritices之间的最短部分吗?

是的,确实如此。已经 proven:

Proof of Dijkstra's algorithm is constructed by induction on the number of visited nodes.

Invariant hypothesis: For each visited node v, dist[v] is considered the shortest distance from source to v; and for each unvisited node u, dist[u] is assumed the shortest distance when traveling via visited nodes only, from source to u. This assumption is only considered if a path exists, otherwise the distance is set to infinity. (Note : we do not assume dist[u] is the actual shortest distance for unvisited nodes)
The base case is when there is just one visited node, namely the initial node source, in which case the hypothesis is trivial.

Otherwise, assume the hypothesis for n-1 visited nodes. In which case, we choose an edge vu where u has the least dist[u] of any unvisited nodes and the edge vu is such that dist[u] = dist[v] + length[v,u]. dist[u] is considered to be the shortest distance from source to u because if there were a shorter path, and if w was the first unvisited node on that path then by the original hypothesis dist[w] > dist[u] which creates a contradiction. Similarly if there was a shorter path to u without using unvisited nodes, and if the last but one node on that path were w, then we would have had dist[u] = dist[w] + length[w,u], also a contradiction.

After processing u it will still be true that for each unvisited nodes w, dist[w] will be the shortest distance from source to w using visited nodes only, because if there were a shorter path that doesn't go by u we would have found it previously, and if there were a shorter path using u we would have updated it when processing u.

如果图中的所有边权重都是正数,Dijkstra 算法会找到最短路径。但如果图形具有负权重,则它不起作用。为了在具有负边权重的图中找到最短路径,使用了像 Bellman-Ford 这样的算法。