Is p & np in syllabus ?

9,184 views

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

- $Q$ solves the subset-sum problem in polynomial time when the input is encoded in unary
- $Q$ solves the subset-sum problem in polynomial time when the input is encoded in binary
- The subset sum problem belongs to the class $\text{NP}$
- The subset sum problem is $\text{NP-hard}$

### 3 Comments

## 2 Answers

Best answer

Subset problem is NP-Complete - there is reduction proof but I don't remember (Can see the below link). So, (

**C**) and (**D**) are true as an NPC problem is in NP as well as NPH.Now, complexity of $Q$ is $O(nW)$, where $W$ is an integer.

- Input is encoded in unary. So, length of input is equal to the value of the input. So, complexity $= O(nW)$ where both $n$ and $W$ are linear multiples of the length of the inputs. So, the complexity is polynomial in terms of the input length. So, (
**A**) is true. - Input is encoded in binary. So, length of W will be $\lg W$. (for $W=1024$, input length will be just $10$). So, now $W$ is exponential in terms of the input length of $W$ and $O(nW)$ also becomes exponential in terms of the input lengths. So, $Q$ is not a polynomial time algorithm. So, (
**B**) is false.

Correct Answer: $B$

### 11 Comments

Option A false because if the inputs are encoded in unary then Q solves this problem in O(1) time by just multiplying the unary number by N and checks whether it's equal to W or not.

Option B is True because we just need to iterate through the loop because the input is binary every time we have only two choices either add this to the sum or not when sum reaches to w answer is yes if no thought the loop then answer is no. it runs in O(n) time also

Options C and D false because given complexity of Algorithm Q is polynomial.