Data Structures & AlgorithmsVery hardICPC regional · algorithm theory
Problem: Which statement about the subset-sum problem with target S and n items is correct in the standard sense?
- A. It is solvable in O(n) for any S
- B. It is NP-complete only when the items are negative
- C. A bitset or boolean DP solves it in O(n * S), which is pseudo-polynomial in the numeric value of S
- D. It is solvable in O(log S) by binary search
Correct answer: C. A bitset or boolean DP solves it in O(n * S), which is pseudo-polynomial in the numeric value of S
The DP over sums takes O(nS) time, which is polynomial in n and S but not in the input size log S.
More Coding Interview Problems questions
- Problem: Binary lifting on a rooted tree with n nodes uses O(n log n) preprocessing. What is the time for one LCA query?
- Problem: Which statement about building a binary heap from n given elements is correct?
- Problem: Which requirement must be met before the convex hull trick can answer queries in O(1) amortised time per query with a deque?
- Problem: Johnson's algorithm reweights edges with potentials before running Dijkstra. What does the reweighting achieve?
- Problem: Range-add updates and point queries on an array can be done with a Fenwick tree over which representation?
- Problem: What is the expected time of Rabin-Karp string matching with a good polynomial hash?