7

I'm working on this problem:

TSP:
Input: A matrix of distances; a budget b
Output: A tour which passes through all the cities and has length <= b, 
if such a tour exists.

TSP-OPT
Input: A matrix of distances
Output: The shortest tour which passes through all the cities.

Show that if TSP can be solved in polynomial time, then so can TSP-OPT.

Now, the first thing that jumps to mind is that if I knew the cost of the optimal solution, I could just set b to that and voila. And, wouldn't you know it, elsewhere in my book it contains a hint for this very problem:

How do we find the optimum cost? Easy: by binary search.

I think I might be misunderstanding something very badly here. Binary search is meant to find the position of a given item in a sorted list. How exactly could that help me find the optimal cost? I'm genuinely confused. The authors don't elaborate any further, unfortunately.

The only other thing I might think of to solve this problem is to prove that they both reduce to another problem that is NP-complete, which I may end up doing, but still... this bugs me.

2-bits
  • 453
  • 6
  • 12
  • It might help if you told us what the textbook is. – Paul Johnson Dec 08 '10 at 07:31
  • 3
    Interestingly, http://cseweb.ucsd.edu/classes/wi08/cse101/hw/hw7soln.pdf has a rather clear explanation. (which also covers why the binary search does not result in a pseudo-polynomial time algorithm). – lijie Dec 08 '10 at 10:54
  • @lijie: But I'm suspicious of the "you can stop when you've reached the resolution of the minimum edge length in the graph" argument. 2 (possibly non-optimal) tours can differ in length by less than the minimum edge length: there could be k edges in some tour that sum to x, and another k edges in the original graph that sum to y < x, such that replacing the 1st k edges with the 2nd yields a new tour whose length is shorter by x-y, and x-y < min_edge_len. – j_random_hacker Dec 08 '10 at 13:22
  • 1
    @j_random_hacker: I believe that the term "resolution of the min-edge" is actually "resolution of the representation of the edge weights" (otherwise, the point about representing K with logK bits is not going to make sense). If the weights are real numbers, then a binary search might not work, and I can't really think of how to make it work unless TSP actually searches for a tour of length < (strictly) b. – lijie Dec 08 '10 at 14:38
  • @lijie: I think you're right if the edge lengths are integers or use a fixed-point representation (in which case just scale them and they become integers). In that case, the smallest nonzero difference in length between tours is 1 and the biggest possible tour is sum(edges), so binary search works fine in log(sum(edges)) time. But if a floating-point representation is used, the smallest nonzero difference in tour length can be very small, and the sum of edges very large, so even though binary search must eventually terminate, it's not clear that it will terminate quickly enough. – j_random_hacker Dec 08 '10 at 15:15
  • 1
    Even a floating point number has a minimum (non zero) resolution (corresponding to the smallest denormalized number), and with some minimum resolution, the argument still stands (the number of steps just increases by a constant factor -- basically the logarithm is taken to a different base), so it is still an acceptable method. Note that the argument doesn't assume a particular maximum edge weight (it just assumes a _finite_ maximum edge weight). – lijie Dec 08 '10 at 15:25
  • @lijie: Let's imagine an extremely simple FP representation in which only powers of 2 can be represented (i.e. 0 bits of mantissa). Given an integer n requiring log2(n+1) bits of storage, the number represented is 2^n. Then if the longest edge is K, this can be represented in log log K bits, and there are at most s = |E|*(log log K) bits of input. The smallest nonzero size difference is 1, so bisection will take b = log K steps. Rearranging, 2^(s/|E|) = log K = b, so the number of steps b is exponential in the size of the input s in bits. – j_random_hacker Dec 08 '10 at 17:14
  • @lijie: I realise this representation would not allow the results of most arithmetic operations to be represented precisely (the only things that would work would be adding or subtracting 2 identical values, subtracting x/2 from x, and multiplying or divinding by a power of 2) which might refute it. Mind you the same is true to a much lesser degree of real-world FP representations... – j_random_hacker Dec 08 '10 at 17:19
  • 1
    ah! that makes sense. so it is due to the fact that using a floating point representation causes the maximum representable number of length n to be of the form k^(k^n) instead of k^n. ok agreed. and my comment 3 comments ago was wrong. this assumes sums are represented to a higher precision than edge weights. if we also have to represent sums using the same representation, hand-wavily, it feels that a variant of binary search where the representation space is split evenly would still work. – lijie Dec 08 '10 at 17:31

1 Answers1

4

Assume that you have some lower bound l (e.g. 0) and upper bound u (e.g. the sum of all the edge weights). First, attempt to find a solution of total cost <= (l+u)/2. If you succeed, try again for a lower value: (3l+u)/4; if not, try for a higher value: (l+3u)/4.

I would call this a bisection method (Wikipedia) rather than binary search, but the idea is the same. We want to search some range for the optimal value, so we start in the middle and move up if we're too low and down if we're too high.

bnaul
  • 17,288
  • 4
  • 32
  • 30
  • +1 but I'm not yet convinced about the stopping criteria for the bisection. As I said in a comment to lijie, the argument advanced in his linked PDF does not show that it's sufficient to stop when the difference is smaller than the minimum edge length in the graph. (That may in fact be a sufficient condition for correctness, but that argument doesn't prove it.) – j_random_hacker Dec 08 '10 at 13:25