Reference no: EM13330113
1. The subset-sum problem is defined as follows: given a set B of n positive integers and an integer K, can you find a subset of B whose elements' summation is equal to K? Design an algorithm to solve this problem. Address its correctness and running time.
Input: set B of n positive integers {b1, b2,....., bn} and an integer K.
Output: whether there exist such a subset of B called B' its elements summation is equal to K.
B'= BA, where A = {a1, a2,........, an} in which AB= b1a1 +b2a2 +......+ bnan. Where ai is either 0 or 1.
Algorithm:
- For i= 1 to 2n (We have 2n different combinations set to be checked)
1. Create all the possible combinations of Array A and do:
- Compute Sum =
- If Sum = K then there is a subset sum to K. This subset B'= {b1a1, b2a2, ......, bnan}when ai representing 1.
- return the subset B'
- Otherwise return there is no subset sum to K.
The run time is O(2n) since it needs to go through all possible subsets to find the subset that sum to K.
2. Suppose you have a procedure that can partition a set of positive integers into two equal weight subsets. How could you use this procedure to solve the subset-sum problem?
To solve this we use reduction. In which prove that subset-sum problem can be reduce to partition problem and visa versa.
The set B of n positive integers whose element summation is equal to an integer K.
Partition reduces to Subset Sum:
Calculate Sum = , which is the summation of all the given numbers. A partition Subset Sum if K = Sum/2.
Subset Sum reduces to Partition:
Calculate Sum = , which is the summation of all the given numbers.
Calculate some number x= Sum - 2K. Create new set A by add x to the set B {b1, b2,....., bn} {x}, where the summation now is B+x. it is possible to split the numbers in A into some subsets iff they can summing up to K:
Subset sum of B indicates partition of A means the set that adds up to Sum with x form a partition.
Partition of A indicates subset sum of B means the numbers which are put together with x must add up to K. Therefore, a partition exists iff some numbers in the B add up to K.
These reference could help you :
1. Bron, C. and Kerbosch, J. "Algorithm 457: Finding All Cliques of an Undirected Graph." Comm. ACM 16, 48-50, 1973.
2. Tomita, E.; Tanaka, A.; and Takahashi, H. "The Worst-Case Time Complexity for Generating All Maximal Cliques and Computational Experiments." Theor. Comput. Sci. 363, 28-42, 2006.
Create all the possible combinations of array a
: The subset-sum problem is defined as follows: given a set B of n positive integers and an integer K, can you find a subset of B whose elements' summation is equal to K? Design an algorithm to solve this problem. Address its correctness and running..
|
Determine the position of the object
: A converging lens with a focal length of 11.4cmforms a virtual image 7.55mm tall, 16.6cm to the right of the lens. Determine the position of the object
|
Depict the ph curve for the titration solution of weak base
: After completing the calculations below, sketch the pH curve for the titration of 25.0 mL of 0.150 M solution of a weak base, B (Kb = 6.8 x 10^-5), with 0.150 M HI. Indicate the pH
|
Obtain the magnitude of the average force
: A rare isotope facility produces a beam of 7.11E5 nuclei per second of a rare isotope with mass 6.43E26 kg. What is the magnitude of the average force that this beam exerts on the beam stop
|
Find a subset of b whose elements summation is equal to k
: The subset-sum problem is defined as follows: given a set B of n positive integers and an integer K, can you find a subset of B whose elements' summation is equal to K? Design an algorithm to solve this problem. Address its correctness and running..
|
Find the time it takes for the object to strike the ground
: An object has a mass of 0.500kg is released from the top of a building of height 7.00m. Find the time it takes for the object to strike the ground
|
What impulse was applied to the ball during the collision
: A rubber ball of mass 39.0 g is dropped from a height of 1.80 m onto a floor. The velocity of the ball is reversed by the collision with the floor, What impulse was applied to the ball during the collision
|
Find the magnitude of the force between the two blocks
: Two blocks are in contact on a frictionless table. A horizontal force F is applied to m1. If m1 = 1.66 kg, m2 = 3.72 kg, and F = 6.25 N, find the magnitude of the force between the two blocks
|
Estimate the induced dipole moment of an oxygen atom
: The polarizability of large atoms can be estimated by using the formula for the polarizability of a metal sphere, \(\alpha = 4\pi\epsilon a^{3}\), Estimate the induced dipole moment of an oxygen atom
|