The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+9 votes
2.8k 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?

  1. $Q$ solves the subset-sum problem in polynomial time when the input is encoded in unary
  2. $Q$ solves the subset-sum problem in polynomial time when the input is encoded in binary
  3. The subset sum problem belongs to the class NP
  4. The subset sum problem is NP-hard
asked in Algorithms by Veteran (59.6k points)
edited by | 2.8k views
0
Is p & np in syllabus ?
0
Please correct the right option(at the end) to option A instead of B.

1 Answer

+17 votes
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.
  1. 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.
  2. 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.
answered by Veteran (363k points)
edited by
+1
Please explain this ENCODING thing.I am not able to understand how encoding in unary and binary come out to be proportional and exponential to input length respectively..

please explain. If possible, any example will be appreciated .

Thank You
0
@Arjun In part b you said input is encoded in binary so logW. But what about values of n. Won't they be also encoded in binary. And then we can say that Q solves the problem in exponential time with both n and W as exponential inputs.
+1
when input in binary, say 1023, i.e. 10 1's, the time taken will be $(n\times(2^{10})-1)$, which is exponential.
0
@Arjun sir please explain little bit more how a is correct and b is false?
0
"Input is encoded in binary"

I am unable to decode it.

What does it mean that all the n inputs of set S are given in binary?

or W in binary?
0
plz explain this encoding thing properly with a example if possible...
0
Encoded in unary:

magnitude of number represented = length of unary code

Time for the algorithm to run is O(nW) = O(n * n)

Encoded in binary:

magnitude of number represented = O(2 ^ length of binary code)

Time for the algorithm to run is O(nW) = O(n * 2^n)
Answer:

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

42,575 questions
48,566 answers
155,470 comments
63,592 users