Introduction to Algorithms (Bellman-Ford)

Generic S.P. Algorithm

Initialize:            for v in V:
                            d[v] ← ∞
                            Π[v] ← NIL
                        d[s] ← 0

Main:                  Repeat 
                       select edge (u, v) 
Relax edge (u, v):         if d[v] > d[u] + w(u, v):
                               d[v] ← d[u] + w(u, v)
                               Π[v] ← u
                        until you can’t relax any more edges or you’re tired or . . 

  1. Complexity could be exp time
  2. The algorithm will continually relax edges when there are negative cycles present.

Bellman-Ford (G, W, s)

Initializa():
for i = 1 to |v| -1:
    for each edge(u, v) in E
        Relax(u, v, w)

for each edge (u, v) in E:
    if d[v] > d[u] + w(u, v)
        then report -ve cycle exists

Theorem:

If G = (V, E) contains no negative weight cycles, then after Bellman-Ford executes d[v] = δ(s, v) for all v ∈ V .

Corollary:

If a value d[v] fails to converge after |V | − 1 passes, there exists a negative-weight cycle reachable from s.

Longest Simple Path and Shortest Simple Path

Finding the longest simple path in a graph with non-negative edge weights is an NP-hard problem, for which no known polynomial-time algorithm exists. Suppose one simply negates each of the edge weights and runs Bellman-Ford to compute shortest paths. Bellman-Ford will not necessarily compute the longest paths in the original graph, since there might be a negative-weight cycle reachable from the source, and the algorithm will abort. Similarly, if we have a graph with negative cycles, and we wish to find the longest simple path from the source s to a vertex v, we cannot use Bellman-Ford. The shortest simple path problem is also NP-hard.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值