HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Time complexity of an enumeration of SUBSET SUM instances

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
enumerationinstancestimesumsubsetcomplexity

Problem

An instance of the SUBSET SUM problem (given $y$ and $A = \{x_1,...,x_n\}$ is there a non-empty subset of $A$ whose sum is $y$) can be represented on a one-tape Turing Machine with a list of comma separated numbers in binary format.
If $\Sigma = \{0,1,\#\}$ a reasonable format could be:

$( 1 \; (0|1)^ \; \#)^ \#$

Where the first required argument is the value $y$ and $\#\#$ encodes the end of the input. For example:

1  0  0  #  1  0  #  1  #  #
^^^^^^^^     ^^^^     ^
   y          x1     x2
Instance: y=4, A={2,1}


I would like to enumerate the SUBSET SUM instances.

Question: What is the (best) time complexity that can be achieved by a Turing Machine $TM_{Enum}$ that on input $m$ (which can be represented on the tape with a string of size $\log m + 1$) - outputs the $m$-th SUBSET SUM instance in the above format?

EDIT:

Yuval's answer is fine, this is only a longer explanation.

Without loss of generality we set that $y > 0$ and $0

  • convert $m$ to base 3 mapping digit 2 to $\#1$



  • when outputing the i-th intermediate $\#$ calculate $x_i = d_i + x_{i-1}-1$



  • output the trailing $\#\#$



No duplicate instances are generated.

Solution

SUBSET-SUM instances can be encoded in base 3. We have codes for $0,1,\#$. Some codings are invalid, but in that case we can just immediately output $\#\#$ (or $\#$, if we have just written $\#$). Every SUBSET-SUM problem has infinitely many encodings, I hope that's not a problem.

If the input has length $\ell$, then (assuming the tape alphabet has at least 4 symbols) we can do the conversion in time $O(\ell^2)$. I don't know whether this is the "best" time complexity achievable.

Edit: Here is a better encoding. We still have only three input codes, $0,1,\#$. The output string always starts with $1$ and ends with $\#\#$. Further, $\#$ is output as $\#1$. Now each output string is generated once, though several output strings could correspond to the same instance.

As an example, your instance is encoded by "00#0#".

Context

StackExchange Computer Science Q#4794, answer score: 3

Revisions (0)

No revisions yet.