
FloydWarshall(弗洛伊德沃舍尔算法):一种经典的图算法,用于在加权图中计算所有点对之间的最短路径(All-Pairs Shortest Paths, APSP)。它可以处理负权边,但通常要求不存在负权回路(否则最短路无意义)。常见时间复杂度为 **O(n)**。
/fld wrl/
We used FloydWarshall to find the shortest paths between every pair of cities.
我们使用 FloydWarshall 算法来找到每一对城市之间的最短路径。
Although Dijkstra’s algorithm is faster for single-source queries, FloydWarshall is convenient when you need all-pairs shortest paths and can store the full distance matrix.
虽然 Dijkstra 算法在单源查询时更快,但当你需要所有点对最短路径并且能够存储完整距离矩阵时,FloydWarshall 更方便。
这是一个以人名命名的算法:与计算机科学家 Robert W. Floyd(罗伯特弗洛伊德) 和 Stephen Warshall(斯蒂芬沃舍尔) 的相关工作有关。该算法常被描述为一种基于动态规划的逐步“松弛/更新”方法,通过允许中间节点集合逐渐扩大来更新任意两点间最短距离。