A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of...
-
Upload
aleesha-douglas -
Category
Documents
-
view
223 -
download
0
Transcript of A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of...
![Page 1: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/1.jpg)
A Shortest Path AlgorithmA Shortest Path Algorithm
![Page 2: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/2.jpg)
MotivationMotivation
Given a connected, positive weighted graph
Find the length of a shortest path from vertex a to vertex z.
![Page 3: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/3.jpg)
Dijkstra’s Shortest Path AlgorithmDijkstra’s Shortest Path Algorithm
Input: A connected, positive weighted graph,vertices a and z
Output: L(z), the length of a shortest path from a to z
1. Dijkstra(w,a,z,L){2. L(a)=03. for all vertices x ≠a4. L(x)=∞5. T=set of all vertices6. while(z є T){7. choose v є T with minimum L(v)8. T=T-{v}9. for each x є T adjacent to v10. L(x)=min{L(x),L(v)+w(v,x)}11. }12. }
![Page 4: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/4.jpg)
Example 8.4.2Example 8.4.2
Find L(z)
b
ze
f
d
c
a
2
2
1
5
43
4 13
7
2
g6
![Page 5: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/5.jpg)
InitializationInitialization
b
ze
f
d
c
a
2
2
1
5
43
4 13
7
2
g6
∞
∞
∞
∞
∞
∞
∞0
![Page 6: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/6.jpg)
Iteration 1Iteration 1
b
ze
f
d
c
a
2
2
1
5
43
4 13
7
2
g6
∞
∞
∞
∞
∞
∞
∞0
2
1
![Page 7: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/7.jpg)
Iteration 2Iteration 2
b
ze
f
d
c
a
2
2
1
5
43
4 13
7
2
g6
∞
∞
∞
∞
∞0
2
1
4
6
![Page 8: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/8.jpg)
Iteration 3Iteration 3
b
ze
f
d
c
a
2
2
1
5
43
4 13
7
2
g6
4
∞
∞
6
∞0
2
1
4
6
![Page 9: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/9.jpg)
Iteration 4Iteration 4
b
ze
f
d
c
a
2
2
1
5
43
4 16
7
2
g6
4
4
6
6
∞0
2
1
5
![Page 10: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/10.jpg)
Proof of Dijkstra’s AlgorithmProof of Dijkstra’s Algorithm
Basic Step(i=1):
we set L(a)=0, and L(a) is sure the length of a shortest path from a to a. Inductive step: For an arbitrary step i
Suppose for step k<i, L(v) is the length of a shortest path from a to v.
Next, suppose that at the it step we choose v in T with minimum L(v). We will seek a contradiction that if there is a w whose length is less than L(v) then w is not in T.
By way of contradiction, suppose there is a w with L(w)<L(v), wєT. Then, let P be the shortest path from a to w, and let x be the vertex nearest to a on P that is in T and let u be x’s predecessor. The node u must not be in T (because x was the nearest node to a that was in T). By assumption, L(u) was the length of the shortest path from a to u.
Then, L(x) ≤ L(u)+w(u,x) ≤ length of P < L(v). This is a contradiction. So w is not in T.
According to our assumption, every path from a to v has length at least L(v).
a ux w… …
P
![Page 11: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/11.jpg)
Example 2Example 2
b
z
d
c
a
2
3
1
1
1
2
e2
Find L(z)
![Page 12: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/12.jpg)
InitializationInitialization
b
z
d
c
a
2
3
1
1
2
e2
∞
∞
∞
∞
∞01
![Page 13: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/13.jpg)
Iteration 1Iteration 1
b
z
d
c
a
2
3
1
1
2
e2
∞
∞
∞
∞
∞0
a,2
a,1
1
![Page 14: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/14.jpg)
Iteration 2Iteration 2
b
z
d
c
a
2
3
1
1
2
e2
∞
∞
∞0
a,2
a,1 d,2
1
![Page 15: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/15.jpg)
Iteration 3Iteration 3
b
z
d
c
a
2
3
1
1
2
e2
∞
d,2
∞0
a,2
a,1
b,5
1
![Page 16: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/16.jpg)
Iteration 4Iteration 4
b
z
d
c
a
2
3
1
1
2
e2
d,2
∞0
a,2
a,1
b,5
1e,4
![Page 17: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/17.jpg)
Iteration 5Iteration 5
b
z
d
c
a
2
3
1
1
2
e2
d,2
0
a,2
a,1
b,5
1e,4
![Page 18: A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.](https://reader035.fdocuments.in/reader035/viewer/2022062516/56649e445503460f94b38121/html5/thumbnails/18.jpg)
Theorem 8.4.5Theorem 8.4.5
For input consisting of an n-vertex, simple, connected, weighted graph, Dijkstra’s algorithm has worst-case run time Ѳ(n2).
Proof: The while loop will take Ѳ(n2) worst-case running time.