Bellmanfordwith negative cycle js
-
Upload
jeesa-sultana -
Category
Education
-
view
107 -
download
0
Transcript of Bellmanfordwith negative cycle js
Welcome To My
Presentation
1
Submitted bySharmin Sultana Jeesa
ID#141-15-3219Sec: C
Dept: CSECourse Code: CSE 221
2
ContentBellman Ford
Algorithm With
Negative Cycle3
InventionoBellman Ford algorithm is
named after two of its developers, Richard Bellman and Lester Ford, Jr. , who published it in 1958 and 1956, respectively.
oHowever, Edward F. Moore also published the same algorithm in 1957, and so it is also sometimes called the Bellman–Ford–Moore algorithm.
4
Bellman Ford Algorithm
oThis is a single source shortest path algorithm.
oThis algorithm can find shortest path from a single source even if the graph contains negative edges.
oBellman–Ford runs in (|V|.|E|) time, where |V| and |E| are the number of vertices and edges respectively.
5
Psuedo Code BELMAN-FORD( G, s ) INIT( G, s ) for i ←1 to |V|-1 do for each edge (u, v) E do RELAX( u, v )
for each edge ( u, v ) E do if d[v] > d[u]+w(u,v) then return FALSE (> neg-weight cycle) return TRUE
6
INIT(G, s) for each v V do d[v] ← ∞
π[v] ← NIL
d[s] ← 0 RELAX(u, v) if d[v] >
d[u]+w(u,v) then
d[v] ← d[u]+w(u,v)
π[v] ← u
Example
7
s
a
b
c
5 -6
4
-2
-9
1st Step
s a b c
0 ∞ ∞ ∞
0
0
0
0
Example
8
s
a
b
c
5 -6
4
-2
-9
1st Step
s a b c
0 ∞ ∞ ∞
0 5 4 ∞
0
0
0
Example
9
s
a
b
c
5 -6
4
-2
-9
1st Step
s a b c
0 ∞ ∞ ∞
0 5 4 ∞
0 5 4 -1
0
0
Example
10
s
a
b
c
5 -6
4
-2
-9
1st Step
s a b c
0 ∞ ∞ ∞
0 5 4 ∞
0 5 4 -1
0 2 4 -1
0 2 -10 -1
Example
11
s
a
b
c
5 -6
4
-2
-9
2nd Step
s a b c0 2 -10 -10 2 -10 -40 -12 -10 -40 -12 -13 -4
Example
12
s
a
b
c
5 -6
4
-2
-9
3rd Step
s a b c0 -12 -13 -40 -12 -13 -180 -15 -13 -180 -15 -27 -18
Example
13
s
a
b
c
5 -6
4
-2
-9
4th Step
s a b c0 -15 -27 -180 -15 -27 -240 -29 -27 -240 -29 -33 -24
According to the Psuedo Code we continue the loop up to v-1, but here we have continued the loop up to v and the value still changing. So here comes a negative(-ve) cycle.
• Though Bellman-Ford algorithm can handle negative edges but it can’t handle negative cycles. It can only detect negative cycles. Even there is no algorithm which can handle negative cycles.
14
Applications• Networks (Routing )• Robot Navigation• Urban Traffic Planning• Telemarketer operator scheduling• Routing of Communication messages• Optimal truck routing through given
traffic congestion pattern• OSPF routing protocol for IP
15
Thank You
16