http://www.diku.dk/PATH05/Uri1.pdf
Strassen’s nn algorithm
View each nn matrix as a 22 matrix whose elements are n/2n/2 matrices.
Apply the 22 algorithm recursively.
T(n) = 7 T(n/2) + O(n^2)
T(n) = O(nlog7/log2)=O(n2.81)
http://cs.anu.edu.au/people/Alistair.Rendell/Teaching/apac_comp3600/module4/all_pairs_shortest_paths.xhtml
The input is an matrix w ij ) .
A recursive solution for the APSP problem is defined. Let ( k ) be the minimum weight of any path from to that contains at most edges.
D ( k ) , W ) for . We only need to run to because that will give us giving us all the shortest path lengths of at most edges (you only need edges to connect vertices). Since SPECIAL-MATRIX-MULTIPLY is called times, the total running time is n^ 4 ) .
Since each matrix contains the shortest paths of at most edges, and really is , all we were doing in the earlier solution was going: "Given the shortests paths of at most length , and the shortests paths of at most length , what is the shortests paths of at most length ?"
This situation is ripe for improvement. The repeated squaring method rephrases the question to: "Given the shortests paths of at most length , what is the shortests paths of at most length ?" The correctness of this approach lies in the observation that the shortests paths of at most edges is the same as the shortest paths of at most edges for all . Thus:
Using repeated squaring, we only need to run SPECIAL-MATRIX-MULTIPLY times. Hence the running time of the improved matrix multiplication is n 3 log n ) .
Figure 1: Example graph for the Repeated Squaring method.
Take the graph in Figure 1 for example. The weights for this graph in matrix form...
Repeatedly squaring this gives us...
contains the all-pairs shortest paths. It is interesting to note that at , the shortest path from to is 9 using the path . Since the final solution ( ) allows for up to edges to be used, a shorter path was found with a weight of 6.
Strassen’s nn algorithm
View each nn matrix as a 22 matrix whose elements are n/2n/2 matrices.
Apply the 22 algorithm recursively.
T(n) = 7 T(n/2) + O(n^2)
T(n) = O(nlog7/log2)=O(n2.81)
http://cs.anu.edu.au/people/Alistair.Rendell/Teaching/apac_comp3600/module4/all_pairs_shortest_paths.xhtml
1 The representation of
|
Algorithms for the APSP problem
- Matrix Multiplication / Repeated Squaring
- The Floyd-Warshall Algorithm
- Transitive Closure of a Graph
3 Matrix Multiplication Algorithm
http://kodu.ut.ee/~eero/PC/Lecture16.pdf
The algorithm is based on dynamic programming, in which each major loop will invoke an operation that is very similar to matrix multiplication. Following the DP strategy, the structure of this problem is, for any two vertices and ,
• Consider the multiplication of the weighted adjacency matrix with itself - except,
in this case, we replace the multiplication operation in matrix multiplication by
addition, and the addition operation by minimization
• Notice that the product of weighted adjacency matrix with itself returns a matrix
that contains shortest paths of length 2 between any pair of nodes
• It follows from this argument that A^n contains all shortest paths
- if , then the shortest path from to is 0.
- otherwise, decompose into , where is a path from to and contains at most edges and it is the shortest path from to .
- If , then
( 0 ) = { 0 if i = j ∞ if i ≠ j - Otherwise, for ,
can be computed from( k ) and the adjacency matrix .( k - 1 ) ( k ) = min { d ij ( k - 1 ) , min 1 ≤ l ≤ n { d il ( k - 1 ) + w lj } } = min 1 ≤ l ≤ n { d il ( k - 1 ) + w lj }
SPECIAL-MATRIX-MULTIPLYThe optimal solution can be computed by calling SPECIAL-MATRIX-MULTIPLY
1 ←
2 ← new matrix
3 for ← to
4 do for ← to
5 do ←
6 for ← to
7 do ←c ij , a ik + b kj )
. /* Here's where this algorithm */
. /* differs from MATRIX-MULTIPLY. */
8 return
3.1 The repeated squaring method
= W
= W 2 = W . W
= W 4 = W 2 . W 2
2 ⌈ log ( n - 1 ) ⌉ ) = W ( 2 ⌈ log ( n - 1 ) ⌉ ) = W ( 2 ⌈ log ( n - 1 ) ⌉ - 1 ) . W ( 2 ⌈ log ( n - 1 ) ⌉ - 1 )
ALL-PAIRS-SHORTEST-PATHS
1 ←
2 ←
3 ←
4 while
5 do ← SPECIAL-MATRIX-MULTIPLYD ( m ) , D ( m ) )
6 ←
7 return
3.2 Repeat Squaring Example
|
|
|