You are not logged in. Please login at www.codechef.com to post your questions!

×

# Equal sum partition

 0 Equal partition: Given a set A of 40 real numbers, find out if there is any way to split A in two sets such that the sums of their elements are equal. (Hint: complexity O(2n/2)) How do I solve this problem using meet in the middle? I found it on this blog. asked 04 Jul '17, 12:43 21●1●3 accept rate: 0%

 2 This problem requires you to divide and conquer. The set of 40 real numbers must be broken to two smaller sets of 20, and merged efficiently. One clever algorithm to do this is Meet in the Middle. A hint for this is you are looking for an aggregate function on the two sets (sum), hence MitM is a possibility. Here is a video editorial I made on Meet in the Middle! Cheers! answered 26 Sep '17, 11:19 4★gkcs 2.6k●1●11●27 accept rate: 9%
 0 don't you understand this explanation? We already know that the 2 subsets we are looking for have the same sum which is equal to the sum of all the elements in the set / 2, so we only need to find the elements of 1 of the 2 subsets. A neat solution would be splitting the set into 2 random disjoint subsets of size N / 2, namely A and B. Then we insert each sum of every combination of elements from A into a hash table. We then check the sums of every combination of elements from B i. e. for a sum K, if S / 2 - K is in the hash, then we have a solution. Final complexity: O(2 ^ (N / 2 + 1)). An alternative to this solution would be a well implemented algorithm which randomly moves elements from one subset to the other. This outperforms the 2 ^ (N / 2) algorithm on memory and may even have better results on time. answered 04 Jul '17, 12:53 1.7k●2●10 accept rate: 14% I went through it before but I couldn't understand. Though I get it now. (04 Jul '17, 14:09)
 0 For anyone else trying to understand it, we are trying to reduce the problem to find a single set of elements whose sum is equal to S/2 where S is sum of all elements in the array. So we divide set of size N(=40) into two halves(=2*20) A and B. Find all possible sums for A array(T = 2^20) and store it in a hash-table. Generate sum of elements from array B and at every step check for a sum K in B array, is there a sum = S/2 - K in the hash-table. If it's there you have your solution. So the first subset will be a collection of all the elements from array A forming sum = S/2 - K and elements from array B (forming sum=K) such that the sum is now S/2 of the complete subset and the second subset has all other elements not included in the first subset. answered 04 Jul '17, 14:51 21●1●3 accept rate: 0%
 0 Would this algorithm run efficiently for large inputs (10^10)? answered 12 Jan, 14:49 21●2 accept rate: 0%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×326
×70

question asked: 04 Jul '17, 12:43

question was seen: 5,407 times

last updated: 12 Jan, 14:49