Subset-sum problem

Assignment Help Theory of Computation
Reference no: EM13189429

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 = 1028_Create all the possible combinations of Array.png

-  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 = 155_Create all the possible combinations of Array1.png, which is the summation of all the given numbers. A partition ≤ Subset Sum if K = Sum/2.

 

Subset Sum reduces to Partition:

Calculate Sum = 155_Create all the possible combinations of Array1.png, 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} U {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.

Reference no: EM13189429

Questions Cloud

What is the ordered pair that defines the y-intercept : Given the quadratic equation y = 5x2-3x+7 .What is the ordered pair that defines the y-intercept?
Discuss the black legend : Discuss the Black Legend and how to compare this legend to what Spain's approach was to exploration, conquest, and colonization. do you think Spanish were worse, better, or about the same as other Europeans?
Derive the euler-lagrange differential equation : Derive the Euler-Lagrange Differential Equation (rigorously). Explain any theorems or results that you use in the derivation (e.g. don't just say "by the fundamental theorem of the calculus of variations" without telling what the fundamental theor..
What are initial levels of real gdp and labor productivity : In the economy of Cape Despair, the subsistence real wage rate is $15 an hour. Whenever real GDP per hour rises above $15, the population grows, and whenever real GDP per hour of labor falls below this level, the population falls.
Subset-sum problem : Calculate some number x= Sum - 2K. Create new set A by add x to the set B {b1, b2,....., bn} U {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:
Define a relation r on the set of all integers z : Define a relation R on the set of all integers Z by xRy iff x+y = 3k for some integer k. Is R an equivalence relation on Z? Why or why not?
What is the maximum number of chairs : A furniture factory needs 32.5 ft2 of fabric to upholster on a chair. Its Dutch supplier sends the fabric in bolts of exactly 200 m2. What is the maximum number of chairs that can be upholstered by 3 bolts of fabric (1 m = 3.281 ft)?
The heaviest slave trade took place in the what century : An alliance with portugal brought wealth and foreign recognition to kongo, as well as what? The heaviest slave trade took place in the what century?
What is the break-even sales (units) : If fixed costs are $300,000, the unit selling price is $31, and the unit variable costs are $22, what is the break-even sales (units) if fixed costs are reduced by $30,000?

Reviews

Write a Review

Theory of Computation Questions & Answers

  Create a method that perform a division operation

Create a method that will perform a division operation on the numbers passed to it in two variables and outputs the results. Use a try catch pair to output an error message if the illegal operation of divide through zero occurs.

  Create a parser to check expression for allowable form

Find out its grammatical structure with respect to given formal grammar. You are needed to create a parser which will check expression for allowable form.

  Show polynomial-time algorithm for gdp

Goal is to find expedition of maximum profit. Either show that there exists polynomial-time algorithm for GDP, or show that corresponding decision problem is NP-complete.

  How does the cell phone help children to communicate

How does the cell phone help children to communicate and are the parents usually encouraging their children to communicate by cell phone?

  Explain proof of rice-s theorem for infinite language

If you perform reduction in proof of Rice's theorem for special case of property P: "infinite language", does this reduction also show that language P L = { | N is Turing machine.

  Question about perfect programming language

I have noticed that there are several languages, is this because no one language has all the main elements needed to be a perfect programming Language?

  Design unambiguous grammar to parse expressions

Write a program would read two numbers and then print all numbers between the first and the second, inclusive. Design unambiguous grammar to parse expressions

  Deterministic finite and non-deterministic finite automata

Describe the difference between a Deterministic Finite Automata and Non-Deterministic Finite Automata. In general, which one is expected to have less number of states ?

  Impact of moore-s law on data center costs

Discuss the impact of Moore's law on data center costs on such things as servers and communications equipment. List at least 3 steps or recommendations your data center can take to offset some or all of the effect of Moore's law.

  Productions of nonterminals as right regular grammars

Rewrite the productions for each of the following nonterminals as right regular grammars: Identifier, Float. Show the moves made using the DFSA for identifiers in accepting.

  Equivalence classes to construct minimal dfa for language

How many equivalence classes does this relation have and what are they? Use these equivalence classes to construct the minimal DFA for the language.

  Implement finite state machine to recognze input string

Write implememnt finite state machine which recognzes input string according to following rules. First character should be either letter(upper or lower case.)

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