Question

In: Computer Science

Suppose we are given a set ? containing 2? integers, and we wish to partition it...

Suppose we are given a set ? containing 2? integers, and we wish to partition it into two sets ?1 and ?2 so that |?1 | = |?2 | = ? and so that the sum of the numbers in ?1 is as close as possible to the sum of those in ?2. Let the neighborhood ? be determined by all possible interchanges of two integers between ?1 and ?2. Is ? exact?

Solutions

Expert Solution

Here the given set S containing 2n integers, After partitioning each set contains n elements. and summation of the elements of s1 is as close as possible s2 means the difference is minimum when we subtract the sums of s1 and s2.

this can be achieved 1st compare one element of S1 with all the elements of S2 by using recursion .then compare elements of S2 with every element of S1.

Example: A={1,2,3,4} here we can divide it into S1={1,4} and S2={2,3} here 1+4=2+3.

example:2 if we need sum=8 then if an array contains 4 elements and we need to divide into equal partitions then if one element is 5 and another one must be 3 if one is 7 and another element is 1.so for each sum and formation partition.

As this can be achieved by using recursion or by using knapsack problem, there is no exact number of interchange because the sum can change from one problem to another and the number of elements in each subset change according to required example if S contains 6 elements each subset contain 3 elements .if S contains 8 elements then each subset contain 4 elements according to that to achieve sum the values of the elements also changed so it is depended on dynamic programming so there is no exact interchange in comparison.


Related Solutions

Suppose that two integers from the set of 8 integers {1, 2, … , 8} are...
Suppose that two integers from the set of 8 integers {1, 2, … , 8} are choosen at random. Find the probability that 5 and 8 are picked. Both numbers match. Sum of the two numbers picked is less than 4. [3+3+4 marks] Suppose that you pick a bit string from the set of all bit strings of length ten. Find the probability that: The bit string has the sum of its digits equal to seven. The bit string has...
On a circular array with n positions, we wish to place the integers 1, 2, ......
On a circular array with n positions, we wish to place the integers 1, 2, ... r in order, clockwise, such that consecutive integers, including the pair (r,1) are not in adjacent positions on the array. Arrangements obtained by rotation are considered the same. In how many ways can this be done? Give a combinatorial proof.
We wish to create a partition of the Cartesian plane. Determine if the following sets are...
We wish to create a partition of the Cartesian plane. Determine if the following sets are a partition and explain why or why not. The set of all circles with radius 3 units and varying centers. The set of all circles with varying radii and centered at the point (0,0) (called the origin). Note the origin is a circle with radius zero. The set of all vertical lines.
5. Suppose you are given an n-element array containing distinct integers that are listed in increasing...
5. Suppose you are given an n-element array containing distinct integers that are listed in increasing order. Given a number k, describe a recursive algorithm to find two integers in A that sum to k, if such a pair exists. What is the running time of your algorithm? Java Language....
Suppose you are given an n-element array containing distinct integers that are listed in increasing order....
Suppose you are given an n-element array containing distinct integers that are listed in increasing order. Given a number k, describe a recursive algorithm to find two integers in A that sum to k, if such a pair exists. What is the running time of your algorithm?
Problem 2.3 Suppose that we take the universal set U to be the integers. Let S...
Problem 2.3 Suppose that we take the universal set U to be the integers. Let S be the even integers, letT be the integers that can be obtained by tripling any one integer and adding one to it, and let V be the set of numbers that are whole multiples of both two and three. (i) Write S, T, and V using symbolic notation. (ii) ComputeS∩T, S∩V andT∩V and give symbolic representations that do not use the symbols S, T,...
Determine whether the given relation is an equivalence relation on the set. Describe the partition arising...
Determine whether the given relation is an equivalence relation on the set. Describe the partition arising from each equivalence relation. (c) (x1,y1)R(x2,y2) in R×R if x1∗y2 = x2∗y1.
7-1 Hoare partition correctness The version of PARTITION given in this chapter is not the original...
7-1 Hoare partition correctness The version of PARTITION given in this chapter is not the original partitioning algorithm. Here is the original partition algorithm, which is due to C. A. R. Hoare: HOARE-PARTITION.A; p; r/ 1 x D AOEp 2 i D p 1 3 j D r C 1 4 while TRUE 5 repeat 6 j D j 1 7 until AOEj x 8 repeat 9 i D i C 1 10 until AOEi x 11 if i <...
Following is the algorithm of Quicksort for sorting an array of integers in ascending order. Partition(numbers,...
Following is the algorithm of Quicksort for sorting an array of integers in ascending order. Partition(numbers, lowIndex, highIndex) {    midpoint = lowIndex + (highIndex - lowIndex) / 2    pivot = numbers[midpoint]    done = false    while (!done) {       while (numbers[lowIndex] < pivot)          lowIndex++       while (pivot < numbers[highIndex])          highIndex--       if (lowIndex >= highIndex) {          done = true       }       else {          temp = numbers[lowIndex]          numbers[lowIndex] = numbers[highIndex]          numbers[highIndex] = temp                 lowIndex++          highIndex--       }    }    return highIndex } Quicksort(numbers, lowIndex, highIndex) {    if (lowIndex...
In the Week 2 lab, we determined the partition coefficients of benzoic acid between the binary...
In the Week 2 lab, we determined the partition coefficients of benzoic acid between the binary solvent systems CH2Cl2 / H2O and CH2Cl2 / (10% NaHCO3). a. Explain why the observed partition coefficient for CH2Cl2 / H2O is greater than for CH2Cl2 / (10% NaHCO3). b. Compared to CH2Cl2 / H2O, what change would you expect to see in the partition coefficient for benzoic acid if 1M HCl were used as the aqueous solvent? What about 1M NaOH? Why
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT