Bellmanfordwith negative cycle js

16
Welcome To My Presentatio n 1

Transcript of Bellmanfordwith negative cycle js

Page 1: Bellmanfordwith negative cycle js

Welcome To My

Presentation

1

Page 2: Bellmanfordwith negative cycle js

Submitted bySharmin Sultana Jeesa

ID#141-15-3219Sec: C

Dept: CSECourse Code: CSE 221

2

Page 3: Bellmanfordwith negative cycle js

ContentBellman Ford

Algorithm With

Negative Cycle3

Page 4: Bellmanfordwith negative cycle js

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

Page 5: Bellmanfordwith negative cycle js

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

Page 6: Bellmanfordwith negative cycle js

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

Page 7: Bellmanfordwith negative cycle js

Example

7

s

a

b

c

5 -6

4

-2

-9

1st Step

s a b c

0 ∞ ∞ ∞

0

0

0

0

Page 8: Bellmanfordwith negative cycle js

Example

8

s

a

b

c

5 -6

4

-2

-9

1st Step

s a b c

0 ∞ ∞ ∞

0 5 4 ∞

0

0

0

Page 9: Bellmanfordwith negative cycle js

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

Page 10: Bellmanfordwith negative cycle js

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

Page 11: Bellmanfordwith negative cycle js

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

Page 12: Bellmanfordwith negative cycle js

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

Page 13: Bellmanfordwith negative cycle js

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.

Page 14: Bellmanfordwith negative cycle js

• 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

Page 15: Bellmanfordwith negative cycle js

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

Page 16: Bellmanfordwith negative cycle js

Thank You

16