Recall the definition of the Travelling Salesman Problem:
Problem: TSP
Instance: A graph G=(V,E), a function
w:E -> R giving the weight of an edge,
a vertex v0 in V and a number k in R.
Question: Is there a path through G starting at vertex
v0 such that the length of that path is at most k?
Consider the following greedy algorithm for solving TSP:
Greedy-Solve-TSP (G, v0, k)
length = 0
unmark all the vertices
mark v0 as visited
u = v0
while there exist unmarked vertices do:
find an unmarked vertex w such that the
f (u, w) is a minimum,
i.e., find the closest unmarked vertex w
to u
sum = sum + weight of (u, w)
mark w as visited
end while
sum = sum + weight of (w, v0)
if sum <= k then
return "yes"
else
return "no"
end if
Assume "marking" is done with an extra Boolean field in the data structure
for each vertex.
- Assuming a reasonable implementation of weighted graphs, does this
algorithm run in time polynomial in the size of the graph?
- Does this algorithm always give the right answer? Why or why
not?