0% found this document useful (0 votes)
5 views6 pages

Approximate Shortest Paths in Weighted - 2012 - Journal of Computer and System S

Uploaded by

ZD No consta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Approximate Shortest Paths in Weighted - 2012 - Journal of Computer and System S

Uploaded by

ZD No consta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Journal of Computer and System Sciences 78 (2012) 632–637

Contents lists available at SciVerse ScienceDirect

Journal of Computer and System Sciences


www.elsevier.com/locate/jcss

Approximate shortest paths in weighted graphs


Raphael Yuster
Department of Mathematics, University of Haifa, Haifa 31905, Israel

a r t i c l e i n f o a b s t r a c t

Article history: We present an approximation algorithm for the all pairs shortest paths (APSP) problem in
Received 13 October 2010 weighed graphs. Our algorithm solves the APSP problem for weighted directed graphs, with
Received in revised form 5 August 2011 real (positive or negative) weights, up to an additive error of  . For any pair of vertices u , v,
Accepted 6 September 2011
the algorithm finds a path whose length is at most δ(u , v )+  . The algorithm is randomized
Available online 14 September 2011
and runs in Õ (n(ω+3)/2 ) < O (n2.688 ) time, where n is the number of vertices and ω is the
Keywords: matrix multiplication exponent. The absolute weights are allowed to mildly depend upon
Shortest path n, being at most no(1) (we note that even if the weights are constants, δ(u , v ) can be
Weighted graph linear in n, while the error requirement  is a small constant independent of n). Clearly,  -
Approximation additive approximations generalize exact algorithms for integer weighted instances. Hence,
if ω = 2 + o(1), this algorithm is as fast as any algorithm known for integer APSP in directed
graphs, and is more general.
© 2011 Elsevier Inc. All rights reserved.

1. Introduction

Shortest paths problems are among the most fundamental algorithmic graph problems. In the shortest paths problem
we are given a (possibly weighted, possibly directed) graph G = ( V , E ) and a set S ⊂ V × V of pairs of vertices, and are
required to find distances and shortest paths connecting the pairs in S. In the Single Source Shortest Paths (SSSP) problem we
have S = {s} × V for some s ∈ V and in the All Pairs Shortest Paths (APSP) problem we have S = V × V .
Our main result is on the APSP problem. In its most general setting, the graph G = ( V , E ) is a directed graph with real
edge weights that can be positive or negative. Thus, the graph is associated with a weight function w : E → . Algorithms
that manipulate real numbers as pure entities work in the addition-comparison model. In this model the only operations
allowed on pairs of real numbers are additions and comparisons, and each of these operations has unit cost. The fastest
algorithm for the general APSP problem was obtained by Chan [3]. Its runtime for n-vertex graphs is O (n3 log3 log n/ log2 n)
which is almost cubic. This result improved earlier barely sub-cubic algorithms dating back to the first such algorithm
by Fredman [6]. When edge weights are integers, we are no longer restricted to the addition-comparison model, and we
can manipulate the bits of the integral weight. The fastest algorithm for APSP in directed graphs with integer (positive or
negative) weights was obtained by Zwick [12] and runs in Õ (n2+μ ) time,1 where μ < 0.575 is a function of the exponent
of rectangular matrix multiplication. It is assumed here that the weights are small (their absolute value is bounded by
a constant, or, more liberally, at most no(1) ). We note that if (as many researcher find plausible) two n × n matrices can be
multiplied in Õ (n2 ) time, Zwick’s algorithm, as well as an earlier algorithm of algorithm of Alon, Galil, and Margalit [2],
runs in Õ (n2.5 ) time.
The theoretical and practical importance of the APSP problem lead many researchers to look for faster algorithms that
settle for almost shortest paths. The review article [13] contains a detailed survey of such algorithms. There are two nat-
ural ways to approximate shortest paths. The first is by stretch-factor algorithms. These types of algorithms guarantee an

E-mail address: [email protected].


1
Throughout this paper, Õ ( f (n)) stands for f (n)no(1) .

0022-0000/$ – see front matter © 2011 Elsevier Inc. All rights reserved.
doi:10.1016/j.jcss.2011.09.001
R. Yuster / Journal of Computer and System Sciences 78 (2012) 632–637 633

α -stretch factor. Namely, they compute a path whose length is at most α δ(u , v ), where δ(u , v ) is the distance from u to v
(assumed to be positive in this definition), and α > 1. The second is additive approximations (also called surplus approxi-
mations). These types of algorithms guarantee an  -additive error. Namely, they compute a path whose length is at most
δ(u , v ) +  . The fastest stretch-factor algorithm for APSP was obtained by Zwick [12]. His algorithm achieves a stretch of
(1 +  ) in Õ ((nω / ) log( W / )) time. The algorithm assumes that the real weights are all positive and in the interval [1, W ].
If  = 1/nt , and t  0.706, and W = no(1) , then a faster algorithm whose runtime is Õ (nω+0.468t ) was obtained by Roditty
and Shapira [10]. Here and throughout this paper ω < 2.376 denotes the matrix multiplication exponent [4].
Good additive approximations exist for undirected graphs. We mention two notable results. Aingworth, Chekuri, Indyk,
and Motwani [1] obtained a 2-additive APSP algorithm in unweighted undirected graphs that runs in Õ (n2.5 ) time. This was
later improved by Dor, Halperin, and Zwick [5] who obtained a running time of Õ (min{n3/2 m1/2 , n7/3 }). They also obtain an
O (log n)-additive APSP algorithm that runs in almost optimal Õ (n2 ) time.
It is much more difficult to obtain good additive approximations for directed graphs, moreover for the general case where
the weights are real, and possibly negative. One naive approach is to round (up) the real weights to the closest rational
which is a multiple of some O (1/n). This reduces the problem to computing exact solutions in integer weighted directed
graphs where the absolute weights are O (n). However, there is no truly sub-cubic algorithm known that handles such
large integer weights. Likewise, one can obtain a constant additive approximation using the stretch factor approximation
algorithm of Zwick mentioned above, with  = O (1/n). However, this also results in a super-cubic runtime, and, in addition,
does not directly apply to the case of negative edge weights.
Our main result obtains the first truly sub-cubic algorithm that achieves an  -additive approximation. It applies to the
most general setting, where positive and negative real weights are allowed. It is assumed that the absolute value of a weight
is at most no(1) .

Theorem 1.1. Let  > 0 be fixed. Let G = ( V , E ) be a directed graph whose edges have real ( positive or negative) weights, of absolute
value at most no(1) . There is a randomized algorithm that computes APSP in G up to an  -additive error in Õ (n(ω+3)/2 ) time.

We assume that the input graph contains no negative cycles. In other words, for pairs u , v for which δ(u , v ) = −∞, the
result returned by the algorithm is meaningless. Clearly, any  -additive approximation algorithm implies an exact algorithm
for the case of integer weights. The converse, however, is not necessarily true. Hence, the algorithm of Theorem 1.1 is also
an Õ (n(ω+3)/2 ) exact algorithm for the case of small (positive or negative) integer weights. This matches the runtime of the
algorithm of Alon, Galil, and Margalit [2], but is strictly more general than it. In fact, if ω = 2 + o(1), then the runtime of the
algorithm of Theorem 1.1 matches the runtime of the fastest known integer APSP algorithm of Zwick mentioned earlier. The
algorithm of Theorem 1.1, though, is strictly more general as it can handle real weights, while still obtaining an  -additive
error.
The rest of this paper contains the proof of Theorem 1.1 in Section 2 and some concluding remarks and open problems
in Section 3.

2. Proof of the main result

We construct a weight-approximated version of the input graph that is somewhat easier to work with. Let G int be
obtained from G be replacing each weight w (e ) with the weight w int (e ) =  2n 2n
 w (e ). Since 0  w int (e ) −  w (e ) < 1 we
know that whenever δ(u , v ) is finite, then δint (u , v ) is also finite and 0  δint (u , v ) − 2n
 δ(u , v ) < n. Hence, in order to obtain
 -additive approximations of distances in G it suffices to obtain n-additive approximations δ̂int of distances in G int , since
such an approximation implies

δ(u , v )  δ̂int (u , v )  δ(u , v ) +  .
2n
It is our goal, therefore, to compute an approximation δ̂int (u , v ) of lengths of actual paths in G int that satisfies

δint (u , v )  δ̂int (u , v )  δint (u , v ) + n.


Denote by W the maximum absolute value of a weight of an edge of G, and recall that W = no(1) . For any two vertices
u , v we have |δ(u , v )| < nW (from here onwards we will only consider pairs for which δ(u , v ), and thus δint (u , v ), is finite).
Each weight of G int is an integer in {− K , . . . , K } where K = (2W / )n + 1 . Notice, though, that distances in G int can be of
absolute value as large as Õ (n2 ).

2.1. Computing distances for a given subset of pairs

An important part of our algorithm consists of computing exact distances in G int for all pairs in a set of pairs
S × V ∪ V × S, where S is relatively large, but still a small part of V . In other words, we will solve SSSP in G int from
each vertex of S, and solve SSSP in the edge-reversed G int from each vertex of S. It is costly, though, to compute SSSP in
a graph with negative edge weights, such as G int . As observed by Johnson [9], by an appropriate reweighing, we can settle
634 R. Yuster / Journal of Computer and System Sciences 78 (2012) 632–637

algorithm scale( A , M , R )
The algorithm receives a matrix A. It returns a matrix A where elements outside the range
{− M , . . . , M } are changed to ∞ and other elements are scaled to the range {− R , . . . , R }.

 Rai j / M  if − M  ai j  M
ai j ←
+∞ otherwise

return A

Fig. 1. Scaling a matrix with positive and negative entries.

for just one application of SSSP and then reduce the problem to SSSP in a graph with non-negative edge weights. Johnson’s
reweighing consists of running a single application of SSSP from a new vertex, denoted by r, connected with directed √ edges
of weight 0 from r to each vertex of V . Goldberg [7], improving a result of Gabow and Tarjan [8], obtained an O (m n log K )
algorithm for the SSSP problem in directed graphs with integer edge weights of value at least − K (here m = O (n2 ) denotes
the number of edges of the graph). It follows that the reweighing of G int can be obtained in Õ (n2.5 ) time, in our case. The
reweighing consists of assigning vertex weights h( v ) for each v ∈ V (these are the distances from r to v after applying SSSP
from r). The new weight, denoted by w int + (u , v ) is just w int (u , v ) + h(u ) − h( v )  0. It now suffices to compute S S S P from
each vertex of S in G int + (and similarly in its edge-reversed version). This, in turn, can be performed in O (n2 ) time for each
vertex of S, using Dijkstra’s algorithm. We therefore obtain:

Lemma 2.1. Let S ⊂ V . There is an algorithm that computes δint (s, v ) and δint ( v , s) for each s ∈ S and each v ∈ V in Õ (| S |n2 + n2.5 )
time.

Recall that Dijkstra’s algorithm also computes shortest paths trees, hence a representation of shortest paths yielding the
distances can be efficiently computed in the same time.

2.2. Approximating distances that are realized by few edges

Another important part of our algorithm consists of computing approximate distances in G int connecting pairs of vertices
for which there exists a shortest path (realizing the exact distance) that does not use too many edges. More precisely, for
a pair of vertices u , v, let c (u , v ) be the smallest integer k such that δint (u , v ) is realized by a path containing k edges. We
describe a procedure that obtains an n-additive approximation of δint (u , v ) for those pairs u , v having c (u , v )  t, where t
will be chosen later. Notice that if c (u , v )  t, then |δint (u , v )|  K t.
Our procedure is a modified version of the stretch-factor approximation algorithm of Zwick from [12], although the latter
only applies to graphs with positive edge weights. Indeed, let us first show how Zwick’s algorithm can be applied, without
change, in the special case where G (and hence G int ) only has positive edge weights. In this case, each edge of G int is in
{1, . . . , K }. For a given γ > 0, the algorithm from [12] computes paths of stretch at most 1 + γ in time Õ ((nω /γ ) log K ).
If we apply it with γ =  /(2W t ) the running time becomes, in our case, Õ (tnω ). It computes paths of length δ̂int (u , v ), of
stretch at most 1 + γ , for all pairs of vertices of G int . But let us examine what this means for those pairs having c (u , v )  t.
For such pairs we have
 
δ̂int (u , v )  (1 + γ )δint (u , v ) = δint (u , v ) + δint (u , v )  δint (u , v ) + K t  δint (u , v ) + n.
2W t 2W t
The stretch-factor approximation is meaningless when negative weight edges (and hence paths) exist. Still, we can modify
the algorithm from [12] so that its consequence for additive approximations of those pairs for which c (u , v )  t remains
almost intact. The modification will still run in Õ (tnω ) time, but its analysis will be somewhat more involved.
Recall that a weighted directed graph, such as G int , is associated with its distance matrix. This matrix, denoted by D, has
rows and columns indexed by V and has D (u , v ) = w int (u , v ). We assume that diagonal entries are 0 and if there is no
edge from u to v then D (u , v ) = ∞. If D 1 and D 2 are two distance matrices then the matrix C = D 1  D 2 is defined by
C (u , v ) = min w ∈ V D 1 (u , w ) + D 2 ( w , v ). We call C the distance product of D 1 and D 2 . We also denote D 2 = D  D (not to be
confused with the standard matrix product). Notice that D 2 (u , v ) is the exact distance from u to v whenever c (u , v )  2.
Similarly D i = D i −1  D (and which, by associativity, equals also D j  D i − j for any j = 1, . . . , i − 1) has the property that
D i (u , v ) is the exact distance from u to v whenever c (u , v )  i.
It is therefore our goal to approximate the entries of D t (u , v ). We will show how to compute a matrix B so that for any
pair u , v we have D t (u , v )  B (u , v )  D t (u , v ) + n, thereby obtaining an n-additive approximation for those pairs having
c (u , v )  t.
The procedure is based on exact distance products of scaled versions of the matrices to be (distance) multiplied. The
simple algorithm scale( A , M , R ), given in Fig. 1, is a version of the scale algorithm from [12], where the only change is
R. Yuster / Journal of Computer and System Sciences 78 (2012) 632–637 635

algorithm approx-dist-prod( A , B , M , R )
The algorithm receives two n × n matrices A and B. Elements of A and B that are of
absolute value greater than M are replaced by ∞. It returns an approximate distance
product C of A and B based on the resolution parameter R.

C ← +∞
for r ← log2 R to log2 M  do
begin
A ← scale( A , 2r , R )
B ← scale( B , 2r , R )
C ← dist-prod( A , B , R )
C ← min{C , (2r / R )C }
end

return C

Fig. 2. Approximate distance products.

algorithm approx-power( D , t )
B←D
M ← max{|b i j | : |b i j | = ∞}
R ← 4Mt (log2 t )/
R ← 2log2 R 
for s ← 1 to log2 t  do
B ← approx-dist-prod( B , B , M , R )
M ← max{|b i j | : |b i j | = ∞}
return B

Fig. 3. Computing an approximation of D t .

that it also scales matrices with negative entries. The elements of a matrix A in the range {− M , . . . , M } are scaled (and
rounded up) to the range {− R , . . . , R }. Other elements are replaced with infinity. Algorithm scale is used by algorithm
approx-dist-prod( A , B , M , R ), given in Fig. 2, whose code is identical to the one from [12] (but we will apply it on matrices
that also have negative entires). Algorithm approx-dist-prod computes an approximation of the distance product A  B.
Suppose R is a power of 2 and that every finite element in A and B is in {− M , . . . , M }. Let C = A  B and let C be the
matrix obtained by calling approx-dist-prod( A , B , M , R ). The same analysis as in [12] shows that for every i and j,

c i j  c i j  c i j + 2M / R . (1)

We show how to compute an approximation of D t by repeated applications of approx-dist-prod. We will assume that t
is a power of 2, and compute the approximation by repeated squaring, as shown in Fig. 3.
Let us set R to be the smallest power of 2 greater than 4W t (log2 t )/ . Let M s be the value of M that is set during the s’th
iteration in algorithm approx-power. Likewise, let B s be the matrix B during the s’th iteration in algorithm approx-power.
The following lemma establishes bounds on M s and on the entries of B s .

Lemma 2.2. In round s of algorithm approx-power we have:


 s 

s
j
s
Ms  2 K ,
Rj
j =0
 s 

s
2s 2s s j
D (i , j )  B s (i , j )  D (i , j ) + 2 K .
Rj
j =1

Proof. The proof is by induction on s. For s = 1, note that in the first call to approx-dist-prod, each finite element of B = D
has a value in {− K , . . . , K }, and K = M. Thus, by Eq. (1), in the resulting B 1 we have D 2 (i , j )  B 1 (i , j )  D 2 (i , j ) + 2K / R.
The smallest value in B 1 is at least −2K and the largest value is at most 2K + 2K / R. Hence, M 1  2K + 2K / R. We now
636 R. Yuster / Journal of Computer and System Sciences 78 (2012) 632–637

assume that the lemma holds for s − 1 and prove it for s. In the call to approx-dist-prod during iteration s, each finite
element of B = B s−1 has a value in {− M s−1 , . . . , M s−1 }, and M = M s−1 . Thus, in resulting B s we have

B 2s−1 (i , j )  B s (i , j )  B 2s−1 (i , j ) + 2M s−1 / R .


On the other hand, by the induction hypothesis,
 s−1 s−1 
 j
2 s −1 2 s −1 s −1
D ( i , j )  B s −1 ( i , j )  D (i , j ) + 2 K ,
Rj
j =1

from which it follows that


 s−1 s−1 
 j
2s 2s
D (i , j )  B 2s−1 (i , j )  D (i , j ) + 2 K s
.
Rj
j =1

Therefore,
 s −1  s −1  
 j
2s 2s s
D (i , j )  B s (i , j )  D (i , j ) + 2 K + 2M s−1 / R
Rj
j =1
 s−1 s−1   s −1  s −1    s 
 j 2  j 
s
2s s s −1 2s s j
 D (i , j ) + 2 K + 2 K = D (i , j ) + 2 K .
Rj R Rj Rj
j =1 j =0 j =1

Similarly,
 s −1  s −1    s 
 j 
s
j
s s
M s  2M s−1 + 2M s−1 / R = 2M s−1 (1 + 1/ R )  2 K (1 + 1/ R ) = 2 K . 2
Rj Rj
j =0 j =0

Lemma 2.3. The matrix B computed by approx-power satisfies D t (u , v )  B (u , v )  D t (u , v ) + n for all pairs u , v. The running
time of approx-power is Õ (nω t ).

Proof. By our choice of R as the smallest power of 2 greater than 4W t (log2 t )/ we have, from Lemma 2.2, that for s = log t,
 s 

s
j
t t
D (u , v )  B (u , v )  D (u , v ) + t K < D t (u , v ) + t K log2 t / R
Rj
j =1
t t
< D (u , v ) + K  /(4W ) < D (u , v ) + n.
The running time follows from the fact that we apply a polylogarithmic number of calls to dist-prod, which, in turn, runs
in Õ ( Rnω ) = Õ (nω t ), as shown by Yuval [11] (see also [12]).

2.3. Completing the proof of Theorem 1.1

We set t to be the smallest power of two larger than n(3−ω)/2 .


We first apply the algorithm of Lemma 2.3 which computes a value B (u , v ) for each pair of vertices u , v. By Lemma 2.3,
this requires Õ (n(ω+3)/2 ) time. Next, we choose a random subset S ⊂ V consisting of 4n ln n/t vertices. We apply the
algorithm of Lemma 2.1 and obtain δint (s, v ) and δint ( v , s) for each s ∈ S and each v ∈ V . By Lemma 2.1, this requires
Õ (n(ω+3)/2 ) time. For each pair of vertices u , v let

(u , v ) = min δint (u , s) + δint (s, v ).


s∈ S

Notice that the runtime required for computing all the (u , v ) is also Õ (n(ω+3)/2 ).
Our algorithm will return, for each pair u , v, the value

δ̂int (u , v ) = min B (u , v ), (u , v ) .

We claim that with very high probability, δint (u , v )  δ̂int (u , v )  δint (u , v ) + n. Consider a pair of vertices u , v for which
c (u , v ) > t. Let p (u , v ) be some path with c (u , v ) edges, realizing δint (u , v ). As S was chosen randomly, the probabil-
ity that none of the (at least t) internal vertex of p (u , v ) belongs to S is at most (1 − (4 ln n)/t )t < 1/n3 . Hence, with
probability at least 1 − 1/n, S has the property that for each pair u , v with c (u , v ) > t, there is some path with c (u , v )
edges realizing δint (u , v ), containing an internal vertex from S. Assuming S has this property, we have, using the fact
R. Yuster / Journal of Computer and System Sciences 78 (2012) 632–637 637

that sub-paths of shortest paths are shortest paths, that (u , v ) = δint (u , v ) whenever c (u , v ) > t. On the other hand, for
pairs u , v with c (u , v )  t, we have, by Lemma 2.3, that D t (u , v )  B (u , v )  D t (u , v ) + n. But since c (u , v )  t, we have
D t (u , v ) = δint (u , v ), and hence δint (u , v )  B (u , v )  δint (u , v ) + n.
We have proved that, with probability at least 1 − 1/n, for all pairs u , v for which δint (u , v ) is finite, we have
δint (u , v )  δ̂int (u , v )  δint (u , v ) + n. Also notice that our approximation δ̂int (u , v ) represents an actual path having this
length. A data structure representing the actual paths is also easily obtained. For (u , v ) this is obtained by the shortest
path trees constructed by Dijkstra’s algorithm (as noted in the paragraph following Lemma 2.1). For B (u , v ) this is obtained
using the witnesses of dist-prod, as shown in [12]. 2

3. Concluding remarks

The algorithm of Theorem 1.1, running in Õ (n(ω+3)/2 ), is asymptotically as fast as any known algorithm for integer
APSP, if ω = 2 + o(1). Still, for the current known upper bound of ω , Zwick’s algorithm for integer APSP runs faster, in
Õ (n2+1/(4−ω) ) time (and even slightly faster using rectangular matrix multiplication). Although it is of some interest to
improve the runtime of the algorithm of Theorem 1.1 to match the runtime of Zwick’s algorithm, the major task is, clearly,
to break the Õ (n2.5 ) barrier assuming ω = 2 + o(1).

References

[1] D. Aingworth, C. Chekuri, P. Indyk, R. Motwani, Fast estimation of diameter and shortest paths (without matrix multiplication), SIAM J. Comput. 28
(1999) 1167–1181.
[2] N. Alon, Z. Galil, O. Margalit, On the exponent of the all pairs shortest path problem, J. Comput. System Sci. 54 (1997) 255–262.
[3] T.M. Chan, More algorithms for all-pairs shortest paths in weighted graphs, in: Proceedings of the 39th ACM Symposium on Theory of Computing
(STOC), ACM Press, 2007, pp. 590–598.
[4] D. Coppersmith, S. Winograd, Matrix multiplication via arithmetic progressions, J. Symbolic Comput. 9 (1990) 251–280.
[5] D. Dor, S. Halperin, U. Zwick, All pairs almost shortest paths, SIAM J. Comput. 29 (2000) 1740–1759.
[6] M.L. Fredman, New bounds on the complexity of the shortest path problem, SIAM J. Comput. 5 (1976) 49–60.
[7] A.V. Goldberg, Scaling algorithms for the shortest paths problem, SIAM J. Comput. 24 (1995) 494–504.
[8] H.N. Gabow, R.E. Tarjan, Faster scaling algorithms for general graph matching problems, J. ACM 38 (1991) 815–853.
[9] D.B. Johnson, Efficient algorithms for shortest paths in sparse graphs, J. ACM 24 (1977) 1–13.
[10] L. Roditty, A. Shapira, All-Pairs Shortest Paths with a sublinear additive error, in: Proceedings of the 35th International Colloquium on Automata,
Languages, and Programming (ICALP), in: Lecture Notes in Comput. Sci., 2008, pp. 622–633.
[11] G. Yuval, An algorithm for finding all shortest paths using N 2.81 infinite-precision multiplications, Inform. Process. Lett. 4 (1976) 155–156.
[12] U. Zwick, All-pairs shortest paths using bridging sets and rectangular matrix multiplication, J. ACM 49 (2002) 289–317.
[13] U. Zwick, Exact and approximate distances in graphs – A survey, in: Proceedings of the 9th Annual European Symposium on Algorithms (ESA), in:
Lecture Notes in Comput. Sci., 2001, pp. 33–48.

You might also like