Download - Lecture 15 data structures and algorithms
Transcript
![Page 1: Lecture 15 data structures and algorithms](https://reader037.vdocuments.mx/reader037/viewer/2022100601/557cfc4bd8b42a98158b4d84/html5/thumbnails/1.jpg)
Bellman-Ford(Algorithm)
![Page 2: Lecture 15 data structures and algorithms](https://reader037.vdocuments.mx/reader037/viewer/2022100601/557cfc4bd8b42a98158b4d84/html5/thumbnails/2.jpg)
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
![Page 3: Lecture 15 data structures and algorithms](https://reader037.vdocuments.mx/reader037/viewer/2022100601/557cfc4bd8b42a98158b4d84/html5/thumbnails/3.jpg)
Algorithm 1. Initialize
Dn(0) = ∞ for all n != s
Ds(h) = 0 for all h
2. For each successive h >= 0Dn
(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]
![Page 4: Lecture 15 data structures and algorithms](https://reader037.vdocuments.mx/reader037/viewer/2022100601/557cfc4bd8b42a98158b4d84/html5/thumbnails/4.jpg)
2 3
4 5
61
6
2
71
3 1
8
4
8
2
53
213
5
![Page 5: Lecture 15 data structures and algorithms](https://reader037.vdocuments.mx/reader037/viewer/2022100601/557cfc4bd8b42a98158b4d84/html5/thumbnails/5.jpg)
h D2(h) path D3
(h) path D4(h)
pathD5
(h) path
D6(h) path
0 ∞ - ∞ - ∞ - ∞ - ∞ -
1 2 1-2 5 1-3 1 1-4 ∞ - ∞ -
2 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