next up previous
Next: Up: Previous:

Fast APSP

Note that \(D^{(m)} \;=\; D^{(n-1)}\) for all m $\geq$ n-1.

Continue until \(D^{2^{\lceil lg(n-1) \rceil}}\) since \(2^{\lceil lg(n-1) \rceil} \;\geq\; n-1\).

This requires only \(\lceil lg(n-1) \rceil\) matrix products (calls to Extend).

This is called ``repeated squaring''.



Fast-APSP(W)
$\;\;\;\;\;$n = rows(W)
$\;\;\;\;\;$D(1) = W
$\;\;\;\;\;$m = 1
$\;\;\;\;\;$while n-1 > m $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; $\lg n$
$\;\;\;\;\;$ $\;\;\;\;\;$D(2m) = Extend-Shortest-Paths(D(m), D(m)) $\;\;\;\;\;$ $\;\;\;\;\;$; n3
$\;\;\;\;\;$ $\;\;\;\;\;$m = 2m
$\;\;\;\;\;$return D(m)



Running time: $\Theta(n^3 \lg n)$


next up previous
Next: Up: Previous: