The Floyd-Warshall algorithm is a well-known algorithm that determines the shortest path for each pair of vertices in a weighted digraph. The every-case time complexity of the algorithm shows that it performs at the level of Θ(n3), where n is the total number of vertices in the digraph. In this paper, we show that, in a digraph containing a large number of vertices (e.g. 100) with nonnegative edges, it can only save an insignificant amount of computational time through bypassing those intermediate steps performed in the algorithm that make no contributions to the process of determining the shortest path for each pair of vertices in the digraph. Those bypassed intermediate steps correspond to performing unnecessary operations for additions and comparisons in the nested for loops of the optimized algorithm which can count up to an amount of 3n2 – 2n. Since the number of times to perform the unnecessary operations for additions and comparisons for the optimized algorithm is reduced by an amount of quadratic time, while the algorithm without optimization performs at cubic level, the ratio between the former and the latter is expected to drop sharply as n increases. For a weighted digraph containing a large number of vertices, say, 100, the number of times reduced in regard to performing the operations for additions and comparisons is approximately 3% of the total number of times to perform the operations without optimization, which is undoubtedly insignificant from the standpoint of modern computer systems equipped with a tremendous amount of computing power.

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Optimization of the Floyd-Warshall Shortest Path Algorithm

  • Ty Carlson,
  • Gordon Wong

摘要

The Floyd-Warshall algorithm is a well-known algorithm that determines the shortest path for each pair of vertices in a weighted digraph. The every-case time complexity of the algorithm shows that it performs at the level of Θ(n3), where n is the total number of vertices in the digraph. In this paper, we show that, in a digraph containing a large number of vertices (e.g. 100) with nonnegative edges, it can only save an insignificant amount of computational time through bypassing those intermediate steps performed in the algorithm that make no contributions to the process of determining the shortest path for each pair of vertices in the digraph. Those bypassed intermediate steps correspond to performing unnecessary operations for additions and comparisons in the nested for loops of the optimized algorithm which can count up to an amount of 3n2 – 2n. Since the number of times to perform the unnecessary operations for additions and comparisons for the optimized algorithm is reduced by an amount of quadratic time, while the algorithm without optimization performs at cubic level, the ratio between the former and the latter is expected to drop sharply as n increases. For a weighted digraph containing a large number of vertices, say, 100, the number of times reduced in regard to performing the operations for additions and comparisons is approximately 3% of the total number of times to perform the operations without optimization, which is undoubtedly insignificant from the standpoint of modern computer systems equipped with a tremendous amount of computing power.