1

I've been looking through graph algorithms for weighted directed graphs, in particular Floyd's algorithm for the All Pairs Shortest Path Problem. Here is my pseudocode implementation.

Let G be a weighted directed graph with nodes {1,...,n} and adjacency matrix A. Let B_k [i, j] be the shortest path from i to j which uses intermediate nodes <= k.

input A

if i = j then set B[i, j] = 0
  set B[i, j] = 0
else if i != j && there is an arc(i, j)
  set B[i, j] = A[i, j]
else 
  set B[i, j] = infinity

#B = B0
for k = 1 to n:
  for i = 1 to n:
    for j = 1 to n:
      b_ij = min(b_ij, b_ik + b_kj)
return B

I was wondering if this algorithm (complexity O(n^3)) could be adapted to the widest path algorithm with similar complexity:

Given a weighted, directed graph (G, W), for each pair of nodes i, j find the bandwidth of the path from i to j with greatest bandwidth. If there is no path from i to j, we return 0.

Could anyone give me a pseudocode algorithm adapting the Floyd-Warshall algorithm for the widest path problem?

ES5775
  • 11
  • 1
  • Note to future readers: these are both specific cases of the algebraic path problem. Other examples are Gauss–Jordan elimination for solving linear systems and Kleene's algorithm for regular expressions. All the same algorithm at heart, in different semirings. – Arya McCarthy Feb 22 '21 at 05:30

2 Answers2

1

I assume that bandwidth of a path P is the lowest cost of the edges in P.

If you use b_ij = max(b_ij, min(b_ik, b_kj)) instead of b_ij = min(b_ij, b_ik + b_kj) you can solve the widest path problem. Also, 'no path' initialization set B[i, j] = infinity must change to set B[i, j] = -infinity.

The demonstration its practically the same as in the original problem: induction over the first k vertices as intermediate vertices. The running time isn't modified: ϴ(n^3).

Eloy Pérez Torres
  • 1,050
  • 4
  • 14
0

You can use the F-W algorithm by augmenting the graph

You can change the weights of the edges to make them all unique powers of two, with the inverse ordering to the original weights.

That is, given the following graph (as a weighted adjacency matrix):

0  3  2
16 0  1
5  8  0

We transform it into:

0  8  16
1  0  32
4  2  0

We can now simply find the shortest paths on this new graph with Floyd-Warshall, which will be the widest paths on the original graph.

To see this, note that any power of two is larger than all lower powers of two, and thus the shortest path will prioritize minimizing the largest weight, as that minimizes the total weight as well. This is equivalent to avoiding the narrowest paths in the original problem, which is exactly what we wanted.

ADdV
  • 1,162
  • 2
  • 16
  • Although it is a correct solution the running time is way above of O(n^3) since in binary representation the greatest number in the modified matrix could use up to n*(n-1) bits. Then every add operation is Ω(n^2) and since Floyd-Warshall algorithm use O(n^3) add operations its running time in the worst case scenario is ϴ(n^5). – Eloy Pérez Torres Feb 22 '21 at 03:39
  • The original algorithm assumes that the weight function values and the number of nodes (n) are unrelated and because of that they can afford to assume constant time addition and achieve an O(n^3) running time. In this modified algorithm the weight function values are directly related to n because of the way the new weights are constructed and they cannot longer be assumed independent from n, nor state their addition use a constant time since those weights could use up to n*n(n-1) bits (complete graph with distinct weight edges). – Eloy Pérez Torres Feb 23 '21 at 13:56