Data Structures & AlgorithmsModerateGATE CS · ICPC regional

In bitmask DP over subsets of n items, what is the typical total time for the TSP-style recurrence dp[mask][last] with transitions to every next item?

  1. A. O(2ⁿ · n²)
  2. B. O(n · 2ⁿ)
  3. C. O(n!)
  4. D. O(2ⁿ · n³)

Correct answer: A. O(2ⁿ · n²)

There are 2ⁿ · n states and each has up to n transitions, giving O(2ⁿ · n²). The naive enumeration of all n! orders is much slower, and an extra factor of n would only appear if each transition scanned every predecessor again.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic