Solution: The Partition Problem
This review provides a detailed analysis of the ways to solve the partition problem
We'll cover the following...
We'll cover the following...
Solution #1: Brute Force
This problem is very similar to the 0/1 knapsack. It essentially follows the same pattern. This solution tries all the combinations of partitioning the given numbers into two sets to see if any pair of sets has an equal sum.
If S represents the total sum of all the given numbers, then the two equal subsets must have a sum equal to S/2. So our problem is technically to find a subset of the given numbers that has a total sum of S/2.
Pseudocode
for each number 'i'
create a new set which INCLUDES number 'i' if it does not exceed 'S/2', and recursively
process the remaining numbers
create a new set WITHOUT number 'i', and recursively process the remaining items
return true if any of the above sets have a sum equal to 'S/2', otherwise, return false
Time Complexity
The time complexity of the above algorithm is exponential ...