DM Chapter10 6 2
DM Chapter10 6 2
Shortest-Path Problems
Section Summary
Introduction
A Shortest-Path Algorithm
The Traveling Salesperson Problem
Introduction
consider how an airline system can be modeled. We
set up the basic graph model by representing cities
by vertices and flights by edges.
To be
A Shortest-Path Algorithm
To be
A Shortest-Path Algorithm
b 3 c
They are a, b of
4 2
length 4 and a, d of
length 2. 0 a 3 z
It follows that d is the
1
closest vertex to a, 2
and the shortest path 3
from a to d has length
d e
2.
To be
A Shortest-Path Algorithm
We can find the c
b 3
second closest vertex
by examining all 4 2
paths that begin with 0
a 3 z
the shortest path
1
from a to a vertex in 2
the set {a, d}, 3
followed by an edge d e
that has one endpoint
in {a, d} and its other
endpoint not in this
set. To be
A Shortest-Path Algorithm
To be
A Shortest-Path Algorithm
To find the third closest
vertex to a, we need b 3 c
examine only the paths 4 2
that begin with the
shortest path from a to 0 a 3 z
a vertex in the set {a, 1
2
d, b}, followed by an
3
edge that has one d e
endpoint in the set {a,
d, b} and its other
endpoint not in this set.
To be
A Shortest-Path Algorithm
There are three such
paths, a, b, c of length b 3 c
7, a, b, e of length 7, 4 2
and a, d, e of length 5.
Because the 0 a 3 z
shortest of these paths 1
2
is a, d, e, the third
3
closest vertex to a is e d e
and the length of the
shortest path from a to
e is 5.
To be
A Shortest-Path Algorithm
To find the fourth
closest vertex to a, we
need examine only the b 3 c
paths that begin with 4 2
the shortest path from a
to a vertex in the set {a,0 a 3 z
d, b, e}, followed by an 1
2
edge that has one 3
endpoint in the set {a, d e
d, b, e} and its other
endpoint not in this set.
To be
A Shortest-Path Algorithm
There are two such
paths, a, b, c of length b 3 c
7 and a, d, e, z of 4 2
length 6. Because the
0 a 3 z
shorter of these paths
is a, d, e, z, the fourth 1
2
closest vertex to a is z 3
and the length of the d e
shortest path from a to
z is 6.
A Shortest-Path Algorithm
We will now consider the general problem of
finding the length of a shortest path between a
and z in an undirected connected simple weighted
graph.