1

I am looking for an algorithm involving adding unweighted edges to an empty, undirected graph (with vertices) and then for each, updating the table of shortest paths.

An example is if we have vertices 1 to 5. We can see that initially, all of the paths are infinite except for the diagonal entries, i.e.:

  1 2 3 4 5
1 0 i i i i
2 i 0 i i i
3 i i 0 i i
4 i i i 0 i
5 i i i i 0

where i means "infinite". But if we add an edge (1, 2) then the 1-2nd and 2-1st entries of the table are updated:

  1 2 3 4 5
1 0 1 i i i
2 1 0 i i i
3 i i 0 i i
4 i i i 0 i
5 i i i i 0

Now, if we add the edge (2, 3), then obviously the 2-3rd and 3-2nd entires are updated, but also are 1-3rd and 3-1st (which has length 2, since the path is 1->2->3 and 3->2->1):

  1 2 3 4 5
1 0 1 2 i i
2 1 0 1 i i
3 2 1 0 i i
4 i i i 0 i
5 i i i i 0

Now, the more edges and vertices we add, the more complex the problem becomes, since we need to update other entries in the matrix if they are connected. The one fact that I know about this kind of graph is that it is symmetric along the diagonal.

I've been looking at this problem for a few hours and I do not think there is a generic algorithm that will solve the problem for a general unweighted, undirected graph. Are there resources on the problem?

Ryan Dougherty
  • 1,013
  • 8
  • 18
  • The i-jth entry should be the length of the shortest path from vertex i to vertex j. Also, for any 2 vertices i and j, there exists at most 1 edge between them. The graph will be guaranteed to not be fully connected. – Ryan Dougherty Jul 21 '14 at 20:01
  • At most 1 edge. All I am looking for is an algorithm that will update a table similar to the one mentioned above. It will not add all possible edges, only edges that I give as input (i.e. I may only add O(n) edges whereas a fully connected graph has O(n^2) edges). – Ryan Dougherty Jul 21 '14 at 20:10
  • Sorry I had misread, I deleted the comments since they add nothing. – lPlant Jul 21 '14 at 20:16
  • No worries! :-) – Ryan Dougherty Jul 21 '14 at 20:19
  • What research have you done? There's been tons of work on dynamic shortest-path algorithms. You've found the right keywords; the word "dynamic" is indeed the critical word. So what research and searching have you done? You should be able to find plenty of work on this subject. For instance, Wikipedia links to http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.32.9856. Searching on this site and on CSTheory.SE immediately turns up http://cs.stackexchange.com/q/7250/755 and http://cs.stackexchange.com/q/1521/755 and http://cstheory.stackexchange.com/q/9990/5038. – D.W. Jul 21 '14 at 22:34
  • @D.W. Thank you for those. The research I initially did was to see if any dynamic APSP algorithms existed for undirected, unweighted graphs, but I couldn't find anything. – Ryan Dougherty Jul 22 '14 at 14:26
  • @Ryan, all of those should be applicable to your scenario. Any algorithm for directed graphs can be used on undirected graphs (IPlant explained). Any algorithm for weighted graphs can be used for weighted graphs (just set all the weights to 1). Also, any algorithm for single-source shortest paths can be used for all-pairs shortest paths, by re-running it $n$ times (once for each possible source). Thus, each of those results should give you something applicable to your setting. Do you want to post an answer summarizing what this gives you, or edit your question with that information? – D.W. Jul 22 '14 at 16:34
  • Thank you, I think the bit about single source shortest paths gave me an idea. On each edge add, run SSSP on the two vertices that have that edge connecting them and update the corresponding entries in the 2D array. – Ryan Dougherty Jul 22 '14 at 21:37

1 Answers1

3

The paper A New Approach to Dynamic All Pairs Shortest Paths by Camil Demetrescu and Giuseppe F. Italiano gives a solution to the directed version of the problem.

It involves saving two priority queues at each position on the matrix and updating and extracting information from these queues as edges are added. The psuedocode for the algorithm is on page 9 of the link.

For undirected graphs like this one, you could add 2 edges for each edge, one in each direction. This will not affect the time complexity of the algorithm.

D.W.
  • 159,275
  • 20
  • 227
  • 470
lPlant
  • 1,612
  • 9
  • 19
  • Thanks for the papers! For both, the graphs used are directed. Is there a (non-approximate) result for undirected graphs? – Ryan Dougherty Jul 21 '14 at 20:30
  • 2
    Could you outline the algorithm you cite and give a proper reference? That would make your answer more informative and more robust against link rot. – Raphael Jul 21 '14 at 20:38
  • Thank you. What about for unweighted graphs? – Ryan Dougherty Jul 21 '14 at 21:37
  • @Ryan, This answer gives a reasonable algorithm for undirected graphs. There's nothing approximate about it. – D.W. Jul 21 '14 at 22:34
  • @D.W. The approximate part was due to research on the dynamic APSP problem (almost all of the results were "approximate" in the title). – Ryan Dougherty Jul 22 '14 at 14:25