Reference no: EM13330117
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.
What happens to the center of mass of two-particle system
: Two particles lie on an x axis, particle 1 at x = 1 m and particle 2 at x = 2 m. what happens to the center of mass of the two-particle system
|
Find the magnitude and direction of the magnetic force
: A horizontal conductor in a power line carries a current of 5500 A from south to north. Find the magnitude and direction of the magnetic force
|
How fast can it lift the crate
: An electric motor is rated to have a maximum power output of 0.68 hp. how fast (i.e., at what speed) can it lift the crate
|
Explain the molar solubility of the metal hydroxide
: A) A saturated solution of metal hydroxide, M(OH)2, has a pH of 10.05. Calculate the molar solubility and the Ksp for this metal hydroxide. M(OH)2 (s) M2+ + 2OH- (aq) B) What is the molar solubility of this metal hydroxide in 0.10 M M(NO3)2
|
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..
|