Data Structures & AlgorithmsModerateGATE CS · ICPC regional

Assertion (A): Dynamic programming over subsets for TSP needs exponential time in the number of cities. Reason (R): The number of subsets of n cities is 2ⁿ, and every subset must be stored with a last city.

  1. A. Both A and R are true, but R is not the correct explanation of A
  2. B. A is true, but R is false
  3. C. A is false, but R is true
  4. D. Both A and R are true, and R is the correct explanation of A

Correct answer: D. Both A and R are true, and R is the correct explanation of A

The bitmask DP stores dp[mask][last] for all 2ⁿ masks, which is why the time and space are exponential. This explains the assertion directly.

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

Exams that ask this topic