Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice

Problem: Subset-sum (does any subset of n integers sum exactly to a target T?) has a DP solution running in O(n*T). Why is this not considered a true polynomial-time algorithm?

  1. A. Because T can be exponentially large relative to the input's bit length, making O(n*T) only pseudo-polynomial
  2. B. Because O(n*T) is always slower than O(2^n)
  3. C. Because subset-sum has no known DP solution at all
  4. D. Because DP never counts as polynomial time

Correct answer: A. Because T can be exponentially large relative to the input's bit length, making O(n*T) only pseudo-polynomial

T's magnitude isn't bounded by the number of bits needed to encode the input; as T grows exponentially in the input size, O(n*T) grows exponentially too, so it's called pseudo-polynomial, not truly polynomial.

More Coding Interview Problems questions

Exams that ask this topic