Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

Cities J, O, Q, V, X, Y are joined by roads with these travel costs: X–J 4, X–Q 5, X–Y 7, X–V 6, X–O 2, J–Q 8, J–Y 4, J–V 5, J–O 9, Q–Y 11, Q–V 13, Q–O 10, Y–V 17, Y–O 10, V–O 5. A salesman must visit every city exactly once and return to his starting city, minimising the total cost. What is the minimum total cost?

  1. A. 32
  2. B. 21
  3. C. 47
  4. D. 20

Correct answer: A. 32

Bitmask DP over subsets gives the minimum Hamiltonian cycle cost 32. A greedy nearest-neighbour tour costs 32, and an open path (no return leg) can be cheaper at 21.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic