Find a subset of b whose elements summation is equal to k

Assignment Help Software Engineering
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.

Reference no: EM13330113

Questions Cloud

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

Reviews

Write a Review

Software Engineering Questions & Answers

  Star life cycle model

interface design proces, Star Life Cycle as a model for interface Design, Nielsen's usability principles, Shneiderman's eight golden rules

  Developing domain model class diagrams

The stock levels of each item are changed by the system with each purchase. However these levels need to be manually updated by a clerk in certain cases such as shipments of items from manufacturers, refunds, exchanges, etc.

  Software management

SOFT337 – Software Management, Demonstrate the  ability to investigate, gather appropriate sources, analyse, evaluate key challenges and discuss future trends within the chosen area of your choice .

  Explanations on fixing c++ code errors

This technique takes an array of ints as a parameter and returns an array of Booleans. For each element in the parameter array whose value is 0,

  Introduction to the theory of computation

The language define through the equality of two 2DIM-DFA machines on all inputs is un-decidable. The full definition of 2DIM-DFA can be discovered in Sipser's Introduction to the Theory of Computation.

  Describe the design and application of arrays

Describe the design and application of arrays and how an array simplifies program development. Give real-world example.

  Discuss the benefits of each methodology in their design

Describe in detail the developments as well as psychological considerations in building in HCI systems and applications.

  Explain and fix java code errors

The code compiles properly, but when you run, you get the following output, Exception in thread "main" java.land.IndexoutBoundsException:

  Create pdm-cpm diagram for play

Given following information about staging community play on Independence day. Create the PDM / CPM diagram. Find out earliest completion time for play and the critical path.

  Example of an ebusiness on the internet

Discuss some example of an eBusiness on the Internet (WWW). Give a link to that business and a one-paragraph summary as to its focus.

  Solving linear equations and linear inequalities

Discuss briefly and explain software testing as a career path, what skills would be desirable for a software tester.

  Analyze polynomial-time algorithm using black box design

Using black box design and analyze the polynomial-time algorithm which calculates the assignment to variables which satisfies the formula.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd