Download Document

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Knapsack problem wikipedia , lookup

Genetic algorithm wikipedia , lookup

Fisher–Yates shuffle wikipedia , lookup

Computational complexity theory wikipedia , lookup

Clique problem wikipedia , lookup

Selection algorithm wikipedia , lookup

Simplex algorithm wikipedia , lookup

Algorithm characterizations wikipedia , lookup

Fast Fourier transform wikipedia , lookup

Expectation–maximization algorithm wikipedia , lookup

K-nearest neighbors algorithm wikipedia , lookup

Algorithm wikipedia , lookup

Travelling salesman problem wikipedia , lookup

Smith–Waterman algorithm wikipedia , lookup

Time complexity wikipedia , lookup

Factorization of polynomials over finite fields wikipedia , lookup

Transcript
Answering distance queries
in directed graphs using
fast matrix multiplication
Raphael Yuster
University of Haifa
Uri Zwick
Tel Aviv University
1
Single-Source Shortest Paths
SSSP
algorithm
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 in O(mn) time,
[Belman ’58], [Ford ’58]
2
All-Pairs Shortest Paths
APSP
algorithm
n by n
distance
matrix
Input: A weighted directed graph G=(V,E),
where |E|=m and |V|=n.
Output: An nn distance matrix.
Can be solved in:
mn + n2 log n
[Johnson ’77] (with Fibonacci Heaps)
mn + n2 log log n [Thorup ’99, Hagerup ’00, Pettie ’02]
3
Answering distance queries
Generalizes both
SSSP and APSP
Preprocessing:
u,v
data
structure
Query answering:
δ(u,v)
4
Single-source Shortest Paths
in directed graphs with bounded integer edge
weights
Running time
Authors
mn1/2log(n)
mn1/2
[Gabow-Tarjan ’89]
[Goldberg ’95]
For dense graphs,
the running time is O(n2.5) !
5
Assuming bounded integer edge weights:
2.5-ε
O(n )
Can we get an
algorithm
for the SSSP problem?
Can we get an O(n3-ε) algorithm
for the APSP problem?
Yes!
If we are using
fast matrix multiplication
6
All-Pairs Shortest Paths
in directed graphs with bounded integer
weights
Running time
Authors
n2.58
[Zwick ’98]
Improves results of
[Alon-Galil-Margalit ’91] [Takaoka ’98]
7
New result:
Answering distance queries
Directed graphs, bounded integer weights.
Preprocessing
time
Query
time
Authors
n2.38
n
[Yuster-Zwick ’05]
In particular, any n1.38 distances
can be computed in n2.38 time.
For dense enough graphs this improves on
Goldberg’s SSSP algorithm.
n2.38 vs. mn0.5
8
Min-Plus Products
  6  3  10 
 1 3 7 
 8    4






5  2      5      3 0  7
 2
 1  7  5 
 8

 5 2 1 
2

5






C  A B
cij  min {aik  bkj }
k
10
Solving the APSP problem
by repeated squaring
If W is an n by n matrix containing the edge weights
of 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
11
Algebraic
Product
Min-Plus
Product
C  A B
C  A B
cij 
a b
ik kj
k
O(n2.38)
[Strassen ’69]
…
[CoppersmithWinograd ’90]
cij  min{ aik  bkj }
k
The fast algebraic
algorithms cannot
be used, as the
min operation
has no inverse
12
Using matrix multiplication
to compute max-plus products
 c11 c12

 c21 c22







 c '11 c '12

 c '21 c '22








c 'ij  
x
 a11 a12

 a21 a22


 a11
 xa
 x 21




aik  bkj
  b11 b12
 
   b21 b22
 
 
x
x
a12
a22
  b11
  xb
   x 21
 
 
 





Assume: 0 ≤ aij , bij ≤ M
cij  max{aik  bkj }
k
x
x
b12
b22






cij  deg(c 'ij )
k
n2.38
polynomial
products

M
operations per
polynomial product
=
Mn2.38
operations per
max-plus product
13
Trying to implement the
repeated squaring algorithm

Consider an easy case:
all weights are 1.
*
Iteration
Max size
of elements
Cost
1
2
i
log n
1
2
2i
n
n2.38
2·n2.38
2i·n2.38
n·n2.38
14
The preprocessing algorithm
D  W ; BV
Choose a subset of B
for i 1 to log3/2n do of size (9n ln n)/s
{
s  (3/2)i+1
B  rand(B,(9n ln n)/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] }
}
Select the columns of D
whose indices are in B
Select the rows and columns of
D whose indices are in B
15
Twice Sampled Distance Products
In the i-th
iteration, the
set B is of
size n ln n / s,
where s =
(3/2)i
n
D[V,B]*D[B,B]
n
The matrices get
smaller and smaller
but the elements get
larger and larger
=
|B|
n
|B|
|B|
16
Complexity of preprocessing
algorithm
The i-th iteration:
n ln n / s
n ln n / s

n
s=(3/2)i+1
n ln n / s
blocks
The elements are
of absolute value
at most
s
(n/s)2.38  s  s ≤ n2.38
17
The query answering algorithm
δ(u,v)  D[{u},V]*D[V,{v}]
v
u
Query time: O(n)
18
The preprocessing algorithm: Correctness
B1  B 2  B3  …
Let Bi be the i-th sample.
Invariant: After the i-th iteration,
if (uV and vBi) or (vV and uBi)
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
 
1 3
2 2
i
 
1 3
2 2
at most
i
 
1 3
2 2
i
19
The query answering algorithm:
Correctness
Suppose that the shortest path from u to v
uses between (3/2)i and (3/2)i+1 edges
at most
 
1 3
2 2
i
 
1 3
2 2
at most
i
 
1 3
2 2
i
u
v
20