Professional Documents
Culture Documents
849 PVD
SFO
SFO
1843
ORD 1 4 2
1743
1387 (LGA
A)
HNL2555
(AX) 1233 (DFW1120 109
MIA
MIA)
Shortest Paths
a Given a weighted graph and two vertices u and v, we want to
find a path of mimimum total weight between u and v.
Length of a path is the sum of the weights of its edges.
Example:
Shortest path between Providence and Honolulu
a Applications
Internet packet routing
Flight reservations
Driving directions 849 PVD
SFO)
1843
ORD
1743
1387(LGA)
Example:
Tree of shortest paths from Providence
849 PVD)
SFO 1843 ORD
387LGA)
1743
Edge Relaxation
DV] = the distance of v froms
D i v ] = the shortest distance
of v from s found so far
o Consider an edge e =
(4, z) S 1 0 Da]= 75
such that
u is the vertex most recently'
added to the cloud
z is not in the cloud
b
Dijkstra's Algorithm: Details
Alg. Dijkstra(V, E)
Input: A weighted directed graph G=(V, , V={1, 2,.., ni
Output: The distance from vertex 1 to every other vertex in G
a The running time can also be expressed as O(m log n) since the
graph is connected (m> n-2).
10
10
Dijkstra's Shortest Path algorithm practice problem (with source = 1)
Node
ode
6
Node
NOGe
25
Node
Node
].dist
initialize 2345|62
Shortest Path from 1 Cost
V=1 20
1025 1 1
|V 6 0 20 30 35 40 10 25 2 12 20 20
V=22
0 20 30 35 40 10 23 3 12793 20+3+2 25
V 7 0 20 25 35 4010 4 12734 20+3+2+3=28
V 3 0 20 25 28 40 10 |5 1 273945 20+3+2+3+4 32
V=4
020 25 28 32 10 6 16 10 10
7 1927 20 3 23
TIlpath
(final value)
T[V).dist Clv][w]VJ.dist+C[v][w]
|T[W].dist
T[w].dist?_
V 6 W:3 = 10+20 30 True
W:4= 10+25 35 True
W:5 = 10+30= 40 True