Disclaimer: this is not an attempt at solving P vs NP
, but a way for me to better understand the problem.
Let ¥(n)
be the Subset sum problem, n
being the number of inputs.
Trivially, a brute force algorithm can solve ¥(n)
in O(n2^n)
.
Let's Divide et Impera trying to solve the problem using n P
algorithms:
First example, n = 3
:
We want to find a subset which contains a sum to a fixed target T
, we start by checking subsets of cardinality 1
, a single for loop will suffice to check every element in O(n)
.
We next look at subsets of cardinality 2
, we exit the previous for loop, and a double for loop will check every pair in O(2n^2)
.
Same for cardinality 3
, an O(3n^{3})
algorithm will conclude the test.
(Important, it is irrelevant if there are better algorithms for some cases, the point is that we have solved ¥(3)
in P
)
Inductively, ¥(c)
should be solvable in O(cn^c)
, which is indeed a polynomial algorithm, impractical, but still in P
.
Obviously P vs NP
is still an open problem so I'm not here with a proof, I just want a clarification on my reasoning to better understand this interesting problem, thanks.
n
in yourO(cn^c)
? Isn't it the input size, e.g.c
?c
, which can be as big as I want? Or the point is that because the induction is based onO(1)
algorithms, the induction fails?