15750 — Graduate Algorithms — Spring 2009
Miller and Dinitz and Tangwongsan
Assignment 2 Solutions
1
Traveling Salesman
(25 pts.)
In the
traveling salesman problem
we are given
n
cities and all distances between the cities.
A
traveling salesman needs to visit all of these cities in order to sell his product, and then return back
to the one he started at (which is presumably his home). The goal is to minimize the total distance
the salesman needs to travel. More formally, let
C
denote the set of cities we are given, and let
d
(
i, j
)
denote the distance between city
i
and city
j
, where
i, j
∈
C
. Then the goal is to find a bijection
(i.e. an ordering)
f
:
{
1
,
2
, . . . , n
} →
C
that minimizes
∑
n

1
i
=1
d
(
f
(
i
)
, f
(
i
+ 1)) +
d
(
f
(
n
)
, f
(1)).
The trivial algorithm for this problem takes examines every possible ordering and returns whichever
has the minimum total distance. But there are a superexponential number of different orderings
((
n

1)!, to be precise), so this algorithm takes not just superpolynomial, but also superexponential
time! For this problem we are asking you to design an exponential time algorithm; in particular,
you should design an algorithm that runs in time
O
(2
n
×
poly
(
n
)), where
poly
(
n
) denotes any
polynomial function of
n
.
Solution:
We use dynamic programming solve this problem. Assume that the cities are numbered from
1
to
n
. We will be working the following subproblems: for
{
1
} ⊆
S
⊆
[
n
]
and
t
∈
S
, let
T
(
S, t
)
denote
the total distance of the best tour that visits all the cities in
S
starting at city
1
and ending at city
t
.
We establish the following:
T
(
S, t
) =
0
if
S
=
{
1
}
and
t
= 1
min
s
∈
S
\{
t
}
n
T
(
S
\ {
t
}
, s
) +
d
(
s, t
)
o
if

S
 ≥
2
To solve a TSP instance, we compute the table
T
and report
min
t
∈
S
T
([
n
]
, t
) +
d
(
t,
1)
as the total
distance of the optimal tour. The running time of this algorithm is
O
(2
n
n
2
)
: we need to fill at most
2
n
×
n
entries of the table
T
, each of which can be computed in
O
(
n
)
time (just finding the min). We
show by induction on

S

that the above recurrence actually computes what we define
T
(
S, t
)
to be.
Claim:
T
(
S, t
)
, as computed by the above recurrence, is the total distance of the best tour that visits
all the cities in
S
starting at city
1
and ending at city
t
.
Proof.
The base case of

S

is trivially true:
T
(
{
1
}
,
1)
is
0
. Assume inductively that the claim holds
for all
S
and
t
such that

S

=
k
.
Then, let
S
0
of cardinality
k
+ 1
and
t
0
be given.
Suppose for a
contradiction that
τ
is a better tour than what
T
(
S
0
, t
0
)
has found. Let
i
τ
be the city
τ
visited right
before
t
0
, and dist
(
τ
)
be the distance traveled on the tour
τ
. Let
τ
0
be the same as
τ
except it stops
right when it visits
i
τ
, so
dist
(
τ
0
) =
dist
(
τ
)

d
(
t
0
, i
τ
)
<
min
s
∈
S
0
\{
t
0
}
n
T
(
S
0
\ {
t
0
}
, s
) +
d
(
s, t
0
)
o

d
(
t
0
, i
τ
)
≤
T
(
S
0
\ {
i
τ
}
, i
τ
)
,
which is a contradiction to the optimality of
T
(
S
0
\ {
i
τ
}
, i
τ
)
.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
15750
HW 2 Solutions
2
Since any tour that visits all the cities has to pass city
1
, it is not difficult to see that we output the total
distance of the best tour. Finally, to construct an actual ordering of cities, we can trace the table
T
,
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 Algorithms, Trigraph, Convex set, Convex hull, Travelling salesman problem

Click to edit the document details