1

I have a complete weighted directed graph G=(V,A,W) and I want to reduce the density of the graph by deleting arcs as follows: given i,j,k \in V if w(i,j)+w(j,k) <= w(i,k), then we delete arc (i,k). The code is given below, where ad is initially the adjacency matrix of G

        for (int i = 0; i < |V|; ++i)
        {
            for (int j = 0; j < |V|; ++j)
            {
                if(j!=i)
                  {
                     for (int k = 0; k < |V|; ++k)
                         {
                               if(k!=i && k!=j){
                                     if(ad[i][j]==1 && ad[j][k]==1 && w(i,j)+w(j,k) <= w(i,k))
                                           ad[i][k]=0;
                                }
                         } 
                  }
            }
       }

My question is: can this procedure make the resulting graph not connected?

Farah Mind
  • 143
  • 5
  • I would have expected an additional direction requirement on the two arcs `w(i,j)` and `w(j,k)` so that they are in the same direction as `w(i,k)`. Perhaps you implied that but I don't see it stated anywhere, e.g. for `w(A,B)` the direction is always from `A` to `B`. – Guy Coder Aug 18 '22 at 08:47
  • yes, for w(i,j) the arc is directed from i to j – Farah Mind Aug 18 '22 at 09:13
  • Seems like you need a proof. Have you searched for such a proof? I am thinking you could use a proof assistant like [Coq](https://coq.inria.fr/). As such I can not help you further. – Guy Coder Aug 18 '22 at 11:02
  • I have just find a proof, finally the graph remains strongly connected – Farah Mind Aug 18 '22 at 11:51

1 Answers1

1

Assuming no machine arithmetic shenanigans and that w(i, j) is positive whenever i ≠ j, no, you can't disconnect the graph.

For every (i, j) pair, consider a longest (by arc count) walk from i to j whose weight is at most w(i, j). This walk is well defined because i → j has weight at most w(i, j), and the assumptions of positive weights and a finite graph imply that the set of possible walks is finite, hence has a maximum. The algorithm cannot remove any of the arcs on this walk, or else there would be a longer walk. Hence the residual graph is strongly connected.

David Eisenstat
  • 64,237
  • 7
  • 60
  • 120
  • I'm not seeing why if there is an arc that can be removed, then there would have to be a longer walk. Can you elaborate on that? – templatetypedef Aug 29 '22 at 17:11
  • 1
    @templatetypedef if the algorithm removed some arc x -> y, then there exists z such that x -> z -> y was no heavier than x -> y. Accordingly, we can pop z right into the walk between x and y; it's a walk, so we can repeat vertices no problem. – David Eisenstat Aug 29 '22 at 18:34
  • Also somehow I overlooked the `ad[i][j]==1 && ad[j][k]==1` test, so of course we could also just use induction on the number of arcs removed. – David Eisenstat Aug 29 '22 at 18:43