Skip to content
Official PYQ · 2008

GATE CS 2008 Q44 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

The subset-sum problem is defined as follows: Given a set SS of nn positive integers and a positive integer WW, determine whether there is a subset of SS whose elements sum to WW. An algorithm QQ solves this problem in O(nW)O(nW) time. Which of the following statements is false?

Choose one option
View worked solution

Answer: B

The subset-sum problem is a well-known NP-complete problem, which means it is both in NP\text{NP} and is NP-hard\text{NP-hard}. Thus, statements C and D are true.

The algorithm QQ runs in O(nW)O(nW) time. Let us analyze the complexity based on the input encoding:

  • Unary Encoding: The number WW is represented by a sequence of WW ones, so the input size is proportional to WW. The running time O(nW)O(nW) is polynomial with respect to the input size n+Wn + W. Thus, statement A is true.
  • Binary Encoding: The number WW is represented using b=⌈log⁡2(W+1)⌉b = \lceil \log_2(W+1) \rceil bits. The input size is proportional to n+bn + b. Expressing the running time in terms of the input size gives O(n⋅2b)O(n \cdot 2^b), which is exponential in terms of the binary input size. Thus, QQ is a pseudo-polynomial time algorithm and does not run in polynomial time for binary encoding. Statement B is false.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Asymptotic Worst Case Time and Space Complexity questions