1

Given n checks, each of arbitrary (integer) monetary value, decide if the checks can be partitioned into two parts that have the same monetary value.

I'm beyond mind blown on how to solve this. Is there an algorithm to solve this in polynomial time or is this NP-Complete?

3
  • may be this question is better placed in programming puzzle or puzzling Commented Jan 27, 2017 at 1:21
  • @yaitloutou I think the question is much more on-topic here than in puzzling or programming puzzle. At most, maybe it should be posted to cs.stackexchange.com Commented Jan 27, 2017 at 10:03
  • @user31264 thank you for the clarification Commented Jan 27, 2017 at 10:15

2 Answers 2

2

Yes it's an NP complete problem. It's a variation of the subset sum problem.

Sign up to request clarification or add additional context in comments.

6 Comments

Awesome thank you! I was puzzled on this for so long. Curious what if I had N checks of two different values. For example value X and value Y. Then would any algorithm for this be NP complete?
For two different values you can solve simple Diophantine equation. In general case there are pseudo-polynomial algorithms using dynamic programming.
You are wrong, this is can be done with a polynomial complexity using dynamic programming.
@AbdenaceurLichiheb Sorry you're wrong. This is called a "weakly NP complete problem." It can be solved by a dynamic program in time proportional to the magnitude of the numbers. If the numbers aren't limited range, this requires time exponential in the size of the inputs.
Yeah, you are right I didn't know about "weakly NP complete problem" tell know, i thought knapsack problem is not an NP-complete problem, well sorry about calling you're solution wrong!
|
0

Actually you can solve this in O(n*sum/2) using dynamic programming, first sum up all checks into a varaibel sum, then you can perform dp on the checks values (either take it or leave it or take it) and check at the end if that sum is equal to s/2.

1 Comment

Still, this isn't P because sum grows with n. Since the algorithm either takes or leaves a check, for every check, there is exponential complexity.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.