0

I am unable to understand how this partition problem can be thought of as a dynamic programming problem.

I have the following doubts:

1) It is not an optimization problem (or I am unable to see) then why are we applying DP approach to it?

2) DP problems satisfy 2 properties:

  1. Overlapping Subproblems
  2. Optimal Substructure

    But I am unable to see the problem satisfying the above properties.

Partition problem is to determine whether a given set can be partitioned into two subsets such that the sum of elements in both subsets is same.

arr[] = {1, 5, 11, 5}

Output: true

The array can be partitioned as {1, 5, 5} and {11}

arr[] = {1, 5, 3}

Output: false

The array cannot be partitioned into equal sum sets.

2
  • Having verified that the sum of all elements is even (otherwise the answer is obviously false), think in terms of selecting a subset whose sum is half of that total. Commented May 18, 2019 at 15:01
  • Doesn't this question have at least one answer here? Commented May 18, 2019 at 20:30

1 Answer 1

0

The problem is NP-Complete but for smaller constraints it is solvable using dynamic programming.

The recurrence relation will be following:

f(index,sum) = f(index,sum + arr[index]) or f(index+1,sum - arr[index])

and for the base case:

if(index >= arraySize) {
    if ( sum == 0 ) 
        return true;
    else
       return false;

}

The Time complexity and the memory complexity of this function will O( arraySize * maximumSum). So if arraySize * maximumSum is small enough the problem is solvable using dynamic programming.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.