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.
- A. Both A and R are true, but R is not the correct explanation of A
- B. A is true, but R is false
- C. A is false, but R is true
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Assertion (A): Kadane's algorithm can be used to find the maximum subarray sum in O(n) time. Reason (R): It keeps the best sum ending at…
- Assertion (A): Binary search on the answer requires that the feasibility predicate is monotone. Reason (R): Only a monotone predicate lets…
- Assertion (A): The greedy 'largest coin first' is optimal for the coin set {1, 3, 4} when the amount is 6. Reason (R): A coin system whose…
- Which of the following statements about the sliding window technique on arrays with NEGATIVE numbers is/are correct? I. A plain…
- The array [7, 2, 5, 10, 8, 3, 6] must be split into exactly 3 contiguous non-empty parts (order kept). What is the smallest possible value…
- An array has 10^5 values and you need the k-th smallest value among all pair sums a[i] + a[j] with i < j. Which approach is the right fit?