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?
- A. O(2ⁿ · n²)
- B. O(n · 2ⁿ)
- C. O(n!)
- 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.
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
- Which statement about the 'house robber' DP on a line is correct?
- A greedy solution to a scheduling problem sorts jobs by profit and places each into the latest free slot before its deadline. What must…
- A coin-change problem uses coins {1, 3, 4} and asks for the minimum number of coins for each amount. Which statement is correct?
- In the circular array [1, 2, 1], what is the next greater element of the element at index 2 (search continues around the circle, -1 if no…
- Looking from the right, a building is seen if it is strictly taller than every building to its right (the rightmost is always seen). How…
- A list holds 1 to 10. Every node whose 1-based position is a multiple of 3 is deleted. What is the sum of the remaining values?