Lecture 15 data structures and algorithms

472 views
414 views

Published on

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
472
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
33
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Lecture 15 data structures and algorithms

  1. 1. Bellman-Ford(Algorithm)
  2. 2. Bellman-Ford Algorithm s = Source node dij = link from node i to j h = maximum number of links in a path at the current stage of the algorithm Dn (h) = cost of the least cost path from node s to node n under the constraint of no more than h links
  3. 3. Algorithm 1. Initialize Dn(0) = ∞ for all n != s Ds(h) = 0 for all h 2. For each successive h >= 0 Dn(h+1) = Minj [Dj(h) + djn ] The path from s to i terminates with the link from j to i [Step 2 is repeated until none of the cost changes]
  4. 4. 8 5 2 1 2 3 1 2 7 4 6 3 1 8 3 1 5 2 3 5 6 4
  5. 5. h D2(h) path D3(h) 0 ∞ - 1 2 2 path D4(h) path D5(h) path D6(h) path ∞ - ∞ - ∞ - ∞ - 1-2 5 1-3 1 1-4 ∞ - ∞ - 2 1-2 4 1-4-3 1 1-4 2 1-4-5 10 1-3-6 3 2 1-2 3 1-4-5-3 1 1-4 2 1-4-5 4 1-4-5- 6 4 2 1-2 3 1-4-5-3 1 1-4 2 1-4-5 4 1-4-5- 6

×