Data Structures & AlgorithmsModerateCodeforces Div2 D · bitmask DP

Problem: What is the standard time complexity of bitmask DP for the travelling salesman problem on n cities?

  1. A. O(2^n * n^2)
  2. B. O(n!)
  3. C. O(n * 2^n)
  4. D. O(n^3)

Correct answer: A. O(2^n * n^2)

The state is (set of visited cities, last city), giving 2^n * n states with n transitions each. The factorial O(n!) brute force is the trap.

More Coding Interview Problems questions

Exams that ask this topic