shortest path of all vertex pairs

- repeated square, O(n^3*lgn), preceding m-1 edges + weight of one more edge. shortest path is choice of k with minimum weight of L(m)

l(m, i, j) = min(l(m-1, i, k) + w(k, j)), 1=<k<=n, 

L(1) = W

L(m) is, 



n-1<2m<2n+1



- Floyd-Warshall O(n^3)

d(i,j) = min(d(k-1, i, j), d(k-1, i, k) + d(k-1, k, j)

d(i,j) = w(i,j) if k = 0


- Johnson for sparse graph, O(VElgV)

add a start vertex, s, and edges to each vertices. w(s,v)=0

run Bellman-Ford from s,

set h(v) = d(s,v) for each vertex

set w'(u,v) = w(u,v) + h(u) - h(v) for each vertex to make it non-negative

run Dijkstra on each vertex to compute d'(u,v)

d(u,v) = d'(u,v) + h(v) - h(u)



阅读更多
文章标签: algorithm
个人分类: Algorithm
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭