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]
R
be encoded? Perhaps the original question from the exam is worded in a misleading way. – LuxProblem B
a polynomial time algorithm or not? Whether answer 4 makes sense is dependent on this. – Lux(2)
) – Water