algorithm - floyd warshall 中节点之间的距离

标签 algorithm floyd-warshall

This维基百科页面解释了 Floyd Warshall 算法,用于查找图中节点之间的最短路径。维基百科页面使用图像左侧的图表 uses the graph on the left of the image作为起始图(在 k = 0 时的第一次迭代之前),然后显示剩余的迭代(k = 1 等),但它没有解释节点之间数字的重要性以及如何计算这些数字。比如起始图中k=0的时候,为什么1和3之间的边上有一个-2,为什么2和3之间的边上有一个3,这些是怎么计算的?

此外,当 k = 2 时,维基百科页面说,

The path [4,2,3] is not considered, because [2,1,3] is the shortest path encountered so far from 2 to 3.

为什么 [2,1,3] 比 [4,2,3] 短?

最佳答案

边缘上的数字只是权重。它是输入的一部分。该算法不计算它们。

[2, 1, 3] 不短于 [4, 2, 3]。不过,它比 [2, 3] 短。这是唯一重要的事情。

关于algorithm - floyd warshall 中节点之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41087141/

相关文章:

algorithm - 如何找到顶点 i 和 j 之间最多有 S 个顶点的最小路径

python - Floyd Warshall 算法未按预期工作

algorithm - Minimax算法讲解

c - Floyd-Warshall 在 C 中使用负循环

java - 计算房间数量的洪水填充算法

python - 我需要帮助使用包裹递送列表调整算法以找到最短路径

algorithm - 所有对最短路径 - 热重启?

java - 具有列表列表的 Floyd-Warshall 算法实现

php - 如何优化从 php 输入匹配多部分 rar 文件的算法

android - Android 和 iPhone 中使用 AES 256 加密(不同结果)