lecture 12:
DESCRIPTION
Lecture 12:. Shortest-Path Problems. Floyd's Algorithm. Another popular graph optimization problem is All-Pairs Shortest Path. In this problem, you are to compute the minimal path from every node to every other node in a directed weighted graph. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/1.jpg)
Lecture 12:
Shortest-Path Problems
![Page 2: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/2.jpg)
Floyd's Algorithm
Another popular graph optimization problem is All-Pairs Shortest Path. In this problem, you are to compute the minimal path from every node to every other node in a directed weighted graph.
The array shown below is a representation of the directed weighted graph. Each row and column represents a particular node in the graph, while each entry in the body of the array is the weight of an arc connected the corresponding nodes.
![Page 3: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/3.jpg)
Weighted Graphs
![Page 4: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/4.jpg)
Traveling Salesperson Problem (TSP)
A B
C
D
EF
G
H
- 5 7 6 4 10 8 9
8 - 14 9 3 4 6 2
7 9 - 11 10 9 5 7
16 6 8 - 5 7 7 9
1 3 2 5 - 8 6 7
12 8 5 3 2 - 10 13
9 5 7 9 6 3 - 4
3 9 6 8 5 7 9 -
A
B
C
D
E
F
G
H
A B C D E F G H
![Page 5: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/5.jpg)
public static int minAvail(int row){ int minval = int.MaxValue; int imin = -1;
for (int j = 0; j < n; j++) { if (row != j && !used[j] && M[row, j] < minval) { minval = M[row, j]; imin = j; } } return imin;}
Finding the Closest Available Next City
ith
ro
w
jth column
M =
![Page 6: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/6.jpg)
public static void doGreedyTSP(int p){ int k = 0; do { itour[k] = p; tour[k] = L[p]; used[itour[k]] = true; p = minAvail(p); k += 1; } while (k < n);}
Greedy TSP
3 1 0 6
1 1 1 1 0 0 1 0
C B A G
itour
used
tour
A B C D E F G HL
![Page 7: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/7.jpg)
Single Source Shortest Path
Given a weighted graph G find the minimum weight path from a specified vertex v0 to every other vertex.
2
11
11 3
4
5
3
6
v1
v0
v5
v4
v3
v2
The single source shortest path problem is as follows. We are given a directed graph with nonnegative edge weights G = (V,E) and a distinguished source vertex, . The problem is to determine the distance from the source vertex to every vertex in the graph.
Vs
![Page 8: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/8.jpg)
v1 v2 v3 v4 v5
node minimum
list path
v1 v2 v3 v4 v5
5 1 4 - 6
v1 v2 v3 v4 v5
5 1 4 - 6
{2} 3 4 2 6
v1 v2 v3 v4 v5
5 1 4 - 6
{2} 3 4 2 6
{24} 3 3 5
v1 v2 v3 v4 v5
5 1 4 - 6
{2} 3 4 2 6
{24} 3 3 5
{241} 3 5
v1 v2 v3 v4 v5
5 1 4 - 6
{2} 3 4 2 6
{24} 3 3 5
{241} 3 5
{2413} 4
v1 v2 v3 v4 v5
5 1 4 - 6
{2} 3 4 2 6
{24} 3 3 5
{241} 3 5
{2413} 4
2
11
11 3
4
5
3
6
v1
v0
v5
v4
v3
v2
Dijkstra's Algorithm for SSSP
![Page 9: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/9.jpg)
Eulers Formula
Let G be a connected planar simple graph with e edges and v vertices. Let r be the number of regions in a planar representation of G.
Then
r = e - v + 2.
![Page 10: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/10.jpg)
![Page 11: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/11.jpg)
![Page 12: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/12.jpg)
![Page 13: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/13.jpg)
![Page 14: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/14.jpg)
![Page 15: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/15.jpg)
![Page 16: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/16.jpg)
![Page 17: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/17.jpg)
![Page 18: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/18.jpg)
![Page 19: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/19.jpg)
![Page 20: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/20.jpg)
![Page 21: Lecture 12:](https://reader035.vdocument.in/reader035/viewer/2022062801/568143a1550346895db02292/html5/thumbnails/21.jpg)