7

I ran into a question on a midterm exam. Can anyone clarify the answer?

Problem A: Given a Complete Weighted Graph G, find a Hamiltonian Tour with minimum weight.

Problem B: Given a Complete Weighted Graph G and Real Number R, does G have a Hamiltonian Tour with weight at most R?

Suppose there is a machine that solves B. How many times can we call B (each time G and Real number R are given),to solve problem A with that machine? Suppose the sum of Edges in G up to M.

1) We cannot do this, because there is uncountable state.

2) O(|E|) times

3) O(lg m) times

4) because A is NP-Hard, This is cannot be done.

AndyG
  • 39,700
  • 8
  • 109
  • 143
  • problem A is Traveling Salesman Problem – amit Feb 20 '15 at 16:08
  • 3
    I would guess that the intended answer was 2) O(|E|) times, by finding the optimum weight and then trying to remove each edge one by one to see which ones belong to an optimum tour, but this question is poorly constructed. – David Eisenstat Feb 20 '15 at 17:18
  • @DavidEisenstat exactly what I thaught when realizing it's "find the path" (and not only the cost), but that will be O(E+logM) – amit Feb 20 '15 at 17:31
  • @amit, i think, A is NP-hard and is TSP. B is Decision Problem of TSP and is NP-Complete. we have two method to solve A with B, 1- All permutation of vertex and all weights and check it with B. 2) search between numbers [0 to m]. this method maybe near to answer but with real weitghs maybe never reach to answer. (4) is false because also we cannot solve it with A in Poly time but using method 1 we can do it in O(n!), (2) and (3) is false bcause NP-HARd. the (1) is also not appropriate. –  Feb 20 '15 at 18:22
  • Dear @DavidEisenstat please see. –  Feb 20 '15 at 18:23
  • @amit O(log M) is sufficient to determine the exact optimum only if we assume integer weights, which who knows? O(|E|) information-theoretically is enough to determine the exact optimum, but I'm not sure what the actual algorithm would look like. This is more thought than this question deserves. – David Eisenstat Feb 20 '15 at 18:52
  • Please be more specific on how the edge weights are encoded. Are they encoded as nonnegative binary integers? How would `R` be encoded? Perhaps the original question from the exam is worded in a misleading way. – Codor Feb 24 '15 at 13:56
  • @Codor, maybe wrong. but is not given in the question. –  Feb 24 '15 at 14:00
  • I somewhat second David Eisenstat - even supposing that the edge weightes are encoded binary nonnegative inegers, none of the given answers seems correct. – Codor Feb 24 '15 at 14:17
  • would you please add an answer with detail. would you please read fifth comments from top? thanks. @Codor –  Feb 24 '15 at 14:27
  • @nini I have answered in detail, however my answer does not actually clarify the problem in an exhaustive way. Is the algorithm for `Problem B` a polynomial time algorithm or not? Whether answer 4 makes sense is dependent on this. – Codor Feb 24 '15 at 15:39
  • @amit, what do u think about new answers? –  Feb 24 '15 at 21:11
  • @nini, NP or P is not a problem here, we only concern about whether we can ***transform*** A into B by a polynomial time algorithm. (3) seems to be a valid one, which Rontogiannis has pointed out in his answer. – Pham Trung Mar 03 '15 at 02:26
  • @PhamTrung see discussion in comments. His answer only yield approximation to the path's weight, and not the path itself – amit Mar 03 '15 at 14:08
  • @amit Taking into account your comment, I edited the answer by adding a second algorithm. I think it is correct now (although with the new algorithm the correct answer seems to be `(2)`) – Rontogiannis Aristofanis Mar 03 '15 at 18:43
  • 1
    How is this a valid stackoverflow question? – m_power Mar 18 '15 at 16:18

3 Answers3

3

First algorithm

The answer is (3) O(lg m) times. You just have to perform a binary search for the minimum hamiltonian tour in the weighted graph. Notice that if there is a hamiltonian tour of length L in the graph, there is no point in checking if a hamiltonian tour of length L', where L' > L, exists, since you are interested in the minimum-weight hamiltonian tour. So, in each step of your algorithm you can eliminate half of the remaining possible tour-weights. Consequently, you will have to call B in your machine O(lg m) times, where m stands for the total weight of all edges in the complete graph.


Edit:

Second algorithm

I have a slight modification of the above algorithm, which uses the machine O(|E|) times, since some people said that we cannot apply binary search in an uncountable set of possible values (and they are possibly right): Take every possible subset of edges from the graph, and for each subset store a value that is the sum of weights of all edges from the subset. Lets store the values for all the subsets in an array called Val. The size of this array is 2^|E|. Sort Val in increasing order, and then apply binary search for the minimum hamiltonian path, but this time call the machine that solves problem B only with values from the Val array. Since every subset of edges is included in the sorted array, it is guaranteed that the solution will be found. The total number of calls of the machine is O(lg(2^|E|)), which is O(|E|). So, the correct choice is (2) O(|E|) times.


Note:

The first algorithm I proposed is probably incorrect, as some people noted that you cannot apply binary search in an uncountable set. Since we are talking about real numbers, we cannot apply binary search in the range [0-M]

Rontogiannis Aristofanis
  • 8,883
  • 8
  • 41
  • 58
  • We have discussed this idea already, it fails because (1) the OP is asking for the actual path, not only the weight. (2) You are not guaranteed to find the exact cost for real-valued (not integers) weight functions. – amit Mar 03 '15 at 11:35
  • please see yes/no formulation on http://www.seas.gwu.edu/~ayoussef/cs212/npcomplete.html –  Mar 03 '15 at 12:02
  • see TSP formulation with Real number on: http://www.cs.utexas.edu/users/djimenez/utsa/cs3343/lecture22.html –  Mar 03 '15 at 12:08
  • @nini I added a second algorithm which has a total non-polynomial complexity, but uses the machine `O(|E|)` times (answer `(2)`). Since there is no restriction about the algorithm's complexity, but only about the number of calls of the machine, I believe it is correct. – Rontogiannis Aristofanis Mar 03 '15 at 16:13
  • Dear @RontogiannisAristofanis, are you here? –  Mar 04 '15 at 17:38
  • @nini, How can I help you? – Rontogiannis Aristofanis Mar 04 '15 at 19:59
  • now, i'm here, are u here @RontogiannisAristofanis. –  Mar 05 '15 at 18:42
  • Would you please see, end of page. 2: after: Ex: TSP on weighted graph Kn = (V, E, w: E -> Reals), |V| = n, |E| = n-choose-2. .............. in http://www.jn.inf.ethz.ch/education/script/chapter7.pdf –  Mar 05 '15 at 19:39
  • @RontogiannisAristofanis, are u here? –  Mar 06 '15 at 17:10
  • @nini I there something not clear in my answer? If there is, please inform me and i will explain it to you. – Rontogiannis Aristofanis Mar 07 '15 at 13:48
  • why u didn't prefer to talk to me ? if your answer is right i want to approve it . @RontogiannisAristofanis –  Mar 14 '15 at 06:20
  • @nini sorry, I was kind of busy lately. I checked the link you posted, but i couldn't understand the notation that was used, as I am still a high-school student and computer science is like a hobby to me. Anyway, I believe that the second algorithm I described is correct, because if the graph has real weights, then the binary search (described in the first algorithm) will have to continue for ever. I hope I helped :) – Rontogiannis Aristofanis Mar 15 '15 at 08:37
  • @RontogiannisAristofanis, you read page 2 with Example of TSP ? –  Mar 15 '15 at 09:08
1

I believe that choice that was meant to be the answer is 1- you can't do that. The reason is that you can only do binary search on countable sets.

Note that the edges of the graph may even have negative weights, and besides, they may have fractional, or even irrational weights. In that case, the search space for the answer will be the set of all real values less than m.

However,you may get arbitrarily close to the answer of A in Log(n) time, but you cannot find the exact answer. (n being the size of the countable space).

Shervin
  • 409
  • 7
  • 13
  • Good points indeed; however we can suppose that some 'reasonable' encoding of the edge weights is chosen. – Codor Feb 24 '15 at 13:55
1

Supposing that in the encoding of graphs the weights are encoded as binary strings representing nonnegative integers and that Problem B can actually algorithmically be solved by entering a real number and perform calculations based on that, things are apparently as follows.

It is possible to do first binary search over the integral interval {0,...,M} to obtain the minumum weight of a Hamiltonian tour in O(log M) calls to the algorithm for Problem B. As afterwards the optimum is known, we can eliminate single edges in G and use the resulting graph as an input to the algorithm for Problem B to test whether or not the optimum changes. This process uses O(|E|) calls to the algorithm for Problem B to identify edges which occur in an optimal Hamiltonian tour. The overall running time of this approach is O( (|E| + log M ) * r(G)), where r(G) denotes the running time of the algorithm for Problem B taking a graph G as an input. I suppose that r is a polynomial, although the question does not explicitly state this; in total, the overall running time would be polynomially bounded in the encoding length of the input, as M can be computed in polynomial time (and hence is pseudopolynomially bounded in the encoding length of the input G).

That being said, the supposed answers can be commented as follows.

  1. The answer is wrong, as the set of necessary states are finite.
  2. Might be true, but does not follow from the algorithm discussed above.
  3. Might be true, but does not follow from the algorithm discussed above.
  4. The answer is wrong. Strictly speaking, the NP-hardness of Problem A does not rule out a polynomial time algorithm; furthermore, the algorithm for Problem B is not stated to be polynomial, so even P=NP does not follow if Problem A can be solved by a polynomial number of calls to the algorithm for Problem B (which is the case by the algorithm sketched above).
Codor
  • 17,447
  • 9
  • 29
  • 56
  • 4. Is definitely wrong if for no other reason that being NP-hard doesn't mean it can't be done. I don't see anywhere in the question where they ask for a poly time algorithm to solve A (using B). – TravisJ Mar 02 '15 at 13:25
  • please see yes/no formulation on http://www.seas.gwu.edu/~ayoussef/cs212/npcomplete.html –  Mar 03 '15 at 12:02