190 likes | 354 Views
Answering distance queries in directed graphs using fast matrix multiplication. Raphael Yuster. University of Haifa. Uri Zwick. Tel Aviv University. Single-Source Shortest Paths. SSSP algorithm. Distance vector. s. n.
E N D
Answering distance queriesin directed graphs using fast matrix multiplication Raphael Yuster University of Haifa Uri Zwick Tel Aviv University
Single-Source Shortest Paths SSSPalgorithm Distance vector s n Input: A weighted directed graph G=(V,E), where |E|=m and |V|=n, and a source vertex s. Output: The distances from s to all other vertices. Can be solved inO(mn)time,[Belman ’58], [Ford ’58]
All-Pairs Shortest Paths APSPalgorithm n by ndistancematrix Input: A weighted directed graph G=(V,E), where |E|=m and |V|=n. Output: An nn distance matrix. Can be solved in:mn + n2 log n [Johnson ’77] (with Fibonacci Heaps)mn + n2log log n [Thorup ’99, Hagerup ’00, Pettie ’02]
Answering distance queries Generalizes both SSSP and APSP Preprocessing: datastructure u,v δ(u,v) Query answering:
Single-source Shortest Pathsin directed graphs with bounded integer edge weights For dense graphs, the running time is O(n2.5) !
Assuming bounded integer edge weights: Can we get an O(n2.5-ε) algorithmfor the SSSP problem? Can we get an O(n3-ε) algorithm for the APSP problem? Yes! If we are using fast matrix multiplication
All-Pairs Shortest Pathsin directed graphs with bounded integer weights Improves results of [Alon-Galil-Margalit ’91] [Takaoka ’98]
New result:Answering distance queries Directed graphs, bounded integer weights. In particular, any n1.38distances can be computed in n2.38time. For dense enough graphs this improves on Goldberg’s SSSP algorithm.n2.38vs.mn0.5
Solving the APSP problem by repeated squaring If W is an n by n matrix containing the edge weightsof a graph. Then Wn is the distance matrix. D W for i 1 to log2n do D D*D Thus:APSP(n) MPP(n) log n
Min-Plus Product Algebraic Product O(n2.38)[Strassen ’69] … [Coppersmith-Winograd ’90] The fast algebraic algorithms cannot be used, as the min operation has no inverse
Using matrix multiplicationto compute max-plus products Assume: 0 ≤ aij , bij≤ M n2.38polynomial products Mn2.38operations per max-plus product Moperations per polynomial product =
Trying to implement the repeated squaring algorithm Consider an easy case: all weights are 1. *
The preprocessing algorithm • D W ; BV • for i 1 to log3/2n do • { • s (3/2)i+1 • B rand(B,(9nlnn)/s) • D[V,B] min{D[V,B] , D[V,B]*D[B,B] } • D[B,V] min{D[B,V] , D[B,B]*D[B,V] } • } Choose a subset of Bof size (9n ln n)/s Select the columns of D whose indices are in B Select the rows and columns of D whose indices are in B
|B| n |B| |B| Twice Sampled Distance Products D[V,B]*D[B,B] In the i-th iteration, the set B is of size n ln n / s, where s = (3/2)i n n = The matrices get smaller and smallerbut the elements get larger andlarger
Complexity of preprocessing algorithm The i-th iteration: n ln n / s n ln n / s s=(3/2)i+1 The elements are of absolute value at mosts n ln n / s blocks n (n/s)2.38 ss ≤ n2.38
v u The query answering algorithm • δ(u,v) D[{u},V]*D[V,{v}] Query time: O(n)
at most at most The preprocessing algorithm: Correctness Let Bi be the i-th sample. B1 B2 B3 … Invariant: After the i-th iteration, if (uV and vBi)or (vV and uBi)and there is a shortest path from u to v that uses at most(3/2)i edges, then D(u,v)=δ(u,v). Consider a shortest path that uses at most (3/2)i+1 edges
at most at most The query answering algorithm: Correctness Suppose that the shortest path from u to vuses between (3/2)i and (3/2)i+1 edges u v