News for hackers. Stuff that matters.
Re:GetACoder.com: Solve P Vs NP by jlouis on Monday August 16, 2010 @08:21AM (#1607538)
It is funny that the author chose the SUBSET-SUM problem. You may be amazed but this is a special-case of the KNAPSACK problem for which we have:

Fully polynomial approximation schemes.

Pseudo-polynomial time algorithms.

In other words, you may find that for all practical purposes this problem can be solved so fast that it doesn't really warrant the NP-badge in some sense. You can say that the problem is an NP problem which disguises itself as a P problem. It would be really fun to use David Pisingers knapsack algorithm codes, http://www.diku.dk/hjemmesider/ansatte/pisinger/codes.html and then bait the bidder into finding a set for which the algorithm is NOT fast (hint: That is also pretty hard :)

Re:GetACoder.com: Solve P Vs NP by eru on Monday August 16, 2010 @08:35AM (#1607570)
Yes. There's even a conjecture that says that for basically all NP problems all reasonable [1] instances will be solvable in expected polynomial time. Even if P != NP.

[1] Add some hand-waving about probability distributions here.

Re:GetACoder.com: Solve P Vs NP by voidpointer on Monday August 16, 2010 @10:49AM (#1607909)
Does that include factoring large prime numbers? If a good approximation would exist for that, wouldn't that make public-key encryption pretty useless?
Re:GetACoder.com: Solve P Vs NP by jerf on Monday August 16, 2010 @11:22AM (#1608025)
Included in that handwave about probability distributions was a caveat about not being handed pathological instances of problems. Encryption harnesses pathological instances and wouldn't be covered by such a handwave.

(Is there ever any other reason to generate multi-hundred digit numbers and try to factor them? Honest question, if anybody's got a fun answer, though I am asking about something actually useful that you know about, not something hypothetical.)

Re:GetACoder.com: Solve P Vs NP by eru on Monday August 16, 2010 @12:21PM (#1608233)
Actually, it's quite hard to come up with good primes for RSA. They need to avoid lots of properties, because researches have found efficient attacks on numbers with those properties.
Re:GetACoder.com: Solve P Vs NP by eru on Monday August 16, 2010 @12:20PM (#1608223)
Factoring numbers is already suspected to be much easier than NP-complete.

That is because factoring prime numbers is in the intersection between NP and co-NP. Co-NP is the set of problems where a "NO" answer is easily checkable with a certificate. If NP ?= co-NP is as much a question as P ?= NP. (I.e. no known proof either way, but every expects them to be unequal.)

Re:GetACoder.com: Solve P Vs NP by amalcon on Monday August 16, 2010 @10:59AM (#1607941)
Public-key encryption schemes would simply need to avoid reasonable circumstances. I suspect "product of two large primes" falls outside the "reasonable circumstances" for factoring.
Re:GetACoder.com: Solve P Vs NP by eru on Monday August 16, 2010 @12:24PM (#1608236)
It's even harder than that. There are lots of known attacks, if you are not careful with your choice of prime numbers. (`Careful' is equal to `choosing pathological instances'.)
Re:GetACoder.com: Solve P Vs NP by pbhjpbhj on Monday August 16, 2010 @09:33AM (#1607714)
>You can say that the problem is an NP problem which disguises itself as a P problem. It would be really fun to use David Pisingers knapsack algorithm codes, http://www.diku.dk/hjemmesider/ansatte/pisinger/codes.html and then bait the bidder into finding a set for which the algorithm is NOT fast (hint: That is also pretty hard :)

This makes me think that the post could be a phish for programmers with strong maths comp-sci backgrounds, something Googlish?

Please someone try this!

Re:GetACoder.com: Solve P Vs NP by jlouis on Monday August 16, 2010 @12:16PM (#1608213)
That would be fun, but alas, I don't have time. One can simply submit Pisingers "decomp" codes from the page I linked above, but if you do that, you are not the author of the work...
Re:GetACoder.com: Solve P Vs NP by antics on Monday August 16, 2010 @11:37AM (#1608085)
I have a question, as a CS student.

Why is finding a set for which the algorithm does not work (edit:) WELL so hard? I have admittedly not read anything about -- or indeed, heard of -- KNAPSACK, but my impression was that we could estimate running time based on various measures of complexity of the problem. Is this incorrect, or is measuring the complexity of NP problems simply incredibly difficult?

Re:GetACoder.com: Solve P Vs NP by jlouis on Monday August 16, 2010 @12:08PM (#1608193)
For all NP-problems, there are trivial instances. As an example the given instance might have structure which effectively makes it a P-problem. What makes NP-problems interesting is that there are also hard instances where the search breaks down and you end up walking an enormous solution space. Most NP-solvers "cheat" by looking at the structure of an instance in order to cut down the amount of searching it needs. How good they are depends on how good they are at cutting down the solution space. A lot of research is going into this - which is really a bet on P not equal to NP.

The KNAPSACK problem is one of the "weak" NP problems in the sense that there is a pseudo-polynomial solution, see

http://en.wikipedia.org/wiki/Pseudo-polynomial_time

Intuitively, this means that KNAPSACK is still hard, but is easier than most other NP problems. Pisingers codes are so good that for most inputs the algorithm actually terminates quickly. There are still hard instances out there, but there are far between them. This means that a search for a hard instance might actually become rather cumbersome. Further, all realistic instances are probably realistically solvable so the instances we lack are more or less of theoretic interest.

So when you call NP-problems hard it is because it has been proven there are some nasty instances among them for which even the most clever NP-solver algorithm for the problem gives up and resorts to basically searching the whole solution space in exponential time.

Re:GetACoder.com: Solve P Vs NP by antics on Monday August 16, 2010 @02:40PM (#1608731)
But WHY are they trivial? Because we can extract metadata that help us prune the solution pool? And if that's the case for the KNAPSACK problem, does this hold for all such problems?
Re:GetACoder.com: Solve P Vs NP by jlouis on Monday August 16, 2010 @06:29PM (#1609521)
Yes, the idea is to look at the structure of the problem and use the structure to prune the solution pool aggressively. The usual method is Branch-and-bound algorithms, but the wikipedia article does not seem to convey the idea especially well, so dig around for a better reference.

Sometimes we are lucky however and there is more structure to a problem than what BB-algorithms usually give. For KNAPSACK, remember that we have a burglar with a knapsack who has just broken into a house. Each item in the house has a given profit and a given weight. The problem is to maximize the profit while still keeping the weight low enough to be in the knapsack. In the 0-1 KNAPSACK problem, there is only one of each item, so we either have to leave it, 0, or to pick it, 1.

The inherent structure is that we can order the items by the ratio p/w of the profit over their weight. Item with a high p/w ratio tend to be items we need in the knapsack, whereas elements with a low p/w ratio tend not to be. It turns out you can preprocess and prune some elements this way before you start on the BB algorithm.

But for this problem it turns out that there is a critical item, the break item and a window of items around it. If you can identify this window, solving that is enough for solving the whole knapsack problem. There is a theorem from the 80'es stating this. It turns out that for knapsack problems with thousands of items, the window tend to be fairly small, some 20-30 items.

Pisingers codes work by being extremely clever at finding the window. It is a smart BB/Dynprog hybrid and as soon as the window is found, it is almost done.

Of course, there are knapsack instances where the window is almost all of the item set and then the algorithm fail. But it turns out to be rather hard producing an instance from a real-world problem which exhibit the large window structure. Hell, Pisingers codes are often faster than sorting the items by the p/w ratio - which makes for a great discussion on complexity :)

So what did I mean by trivial instances? In the SUBSET-SUM problem, this is a trivial instance: {-3,-2,-1,1,2,3}. This one too: {1,2,-3}. Or how about this one: {1,-1, 337}. In the first two, the whole set works. In the latter, it is easy to see that 337 can never be part of the sum as its inclusion lead to a value so great we can never hope to get back to 0. Even if we construct extremely large sets, it is easy to construct them in a way such they can be pruned down to a small set and then solved.

Re:GetACoder.com: Solve P Vs NP by antics on Tuesday August 17, 2010 @12:03PM (#1611495)
You have been most helpful. Thank you indeed.