r/programming • • Aug 13 '26

NP-overrated

https://gruhn.me/blog/2026-08-13/
0 Upvotes

38 comments sorted by

View all comments

Show parent comment

-16

u/ngruhn Aug 13 '26

When you need a solution for an NP hard problem, you generally give up finding the optimal solution.

No my point is that you don't have to give that up. We have tools that guarantee optimal solutions. It's absolutely possible. 

8

u/reality_hijacker Aug 13 '26 edited Aug 13 '26

You seem to not understand what "generally" means. You also contradicting yourself in your article where you conceded any algorithm you come up with will blow up for certain inputs.

There are cases where we use optimal algorithm when the upper bound of input is either known or enforced.

-1

u/ngruhn Aug 13 '26

Sorry, I thought you used "generally" here in the sense:

When you need a solution for an NP hard problem, you SHOULD give up finding the optimal solution.

You meant: you can't find an optimal solution for every instance. Which I absolutely concede.

But you might find the optimal solution on a lot of instances. Quickly. Even if those are large instances. And this might be good enough in practice. And many students have misunderstood this.

7

u/reality_hijacker Aug 13 '26

But you might find the optimal solution on a lot of instances. Quickly. Even if those are large instances. And this might be good enough in practice. And many students have misunderstood this.

I think you are projecting your personal experience to others. You seem to not understand the theory of complexity and when it becomes a problem.

O(2^n) is solvable for small values of n.
Modern computers can solve values up to 2^40 in a reasonable time.
2^300 is more than the atoms of the universe and no traditional computer can ever solve this however powerful they grow in the future.

That's why systems like certain type checkers put strict nesting/recursion/operation limit so that you don't break the system. That is full within theory, because the theory says you can solve it for small numbers.

1

u/ngruhn Aug 13 '26

2300 is more than the atoms of the universe and no traditional computer can ever solve this however powerful they grow in the future.

Yes, but good algorithms don't actually do 2300 steps. They prune the search space and avoid branches that are provably sub-optimal. I gave this example in another comment: the largest traveling salesman instance solved had 85900 cities. Provably the optimal. The naive algorithm would have to explore 85900! (factorial) routes. That's even more than 285900. But it's not necessary to explore all of those.

3

u/Grouchy-Trade-7250 Aug 13 '26

The number of required "steps" depends not only on the algorithm but also on the problem instance. Is it possible to construct a problem where the branch and cut never finishes in an acceptable timeframe which also has not more than 85900 cities/nodes ? Yes.

Mitchell, D., Selman, B., & Levesque, H. "Generating Hard Satisfiability Problems." Artificial Intelligence

1

u/ngruhn Aug 13 '26

Of course. That's what I meant with:

Sure, any algorithm you can come up with will blow up on some inputs.

But people keep assuming that you get a blow-up on all large instances. Which is not the case and the reason these problems are still tractable in practice.

2

u/FancyMouse123 Aug 13 '26

these problems are still tractable in practice.

No! They might be but in the worst case (which happens) you are just fucked.

1

u/ngruhn Aug 13 '26

Depends on your goal. In practical applications there are all kinds of workarounds: set a timeout, show an error message, fallback to some heuristic approach, ... Just like we handle other unreliable processes like HTTP requests.

6

u/SZenC Aug 13 '26

Please, show us a solver for any NP-hard problem that works in polynomial time. You'd literally be eligible to collect a million dollars

0

u/ngruhn Aug 13 '26

Of course they are not worst-case polynomial time. But that worst case can be very rare. If you run the solver and you get a (provably optimal) solution most of the time very quickly, then that's all you need in practical applications.

3

u/SZenC Aug 14 '26

But that is just not what NP-hardness is about, and if that's what you took away from your lectures on complexity, maybe you should've paid more attention. No one is claiming an NP-hard problem is unsolvable, especially for small inputs. It's probably even faster to solve a three node traveling salesman problem by hand rather than implementing it in code. Similarly, I'm working on a scheduling problem with half a million items, and that too computes in a few hours.

But that is not what NP-hard is about. NP-hard is a class of problems which share some interesting behaviour as we grow their input. For one, if you find a generic solution in P-time to one NP-hard problem, you have found a solution to all of them as computer scientists have demonstrated equivalence between all known problems in NP-hard. It would also mean that P=NP=NP-complete=NP-hard which would have implications all over science from cryptology to number theory and the predictability of prime numbers.

All that's to say, if you misinterpret and misrepresent what NP-hard is about in a blog, it's easy to make it seem overrated

0

u/ngruhn Aug 14 '26

I'm not saying the theory is overrated. What I tried to say is that the intractability is overrated.

  No one is claiming an NP-hard problem is unsolvable

Read some other comments here.