1 the subset-sum problem is defined as follows given a set

Assignment Help Theory of Computation
Reference no: EM13380165

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: EM13380165

Questions Cloud

In numerical integration and in many other cases we need a : in numerical integration and in many other cases we need a polynomial named legendre polynomial. often the zeros i.e.
1 five reactors linked by pipes are shown in the following : 1. five reactors linked by pipes are shown in the following figure. the rate of mass flow through each pipe is computed
1 social changeshow have the recent changes in information : 1. social changeshow have the recent changes in information technology affected society? are these changes for the
Write a program that calculates an employees wage for a : write a program that calculates an employees wage for a week. an employees wage is calculated as followsi if the number
1 the subset-sum problem is defined as follows given a set : 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
1 write a script to help users calculate compressed file : 1. write a script to help users calculate compressed file size. prompt the user to enter the original size of a file
Question 1you are required to undertake a detailed analysis : question 1you are required to undertake a detailed analysis of the avl tree sorting algorithm for avlsort.to do this
1distinguish between the terms lsquoerp implementation and : 1.distinguish between the terms lsquoerp implementation and lsquoerp configuration2.explain the purpose of the entity
Introductionthis is an individual assignment in which you : introductionthis is an individual assignment in which you can explore the use of extensible files in web programming

Reviews

Write a Review

Theory of Computation Questions & Answers

  Q1 consider a computer system with a single processor with

q.1. consider a computer system with a single processor with a single core. there are two processes to run in the

  The roommate problem and intern assignment problem

Implementation of both the algorithms using C/C++ code 1. roommates problem 2. Intern Problem

  1let s1 and s2 be two strings of lengths m and n

1.let s1 and s2 be two strings of lengths m and n respectively. by de?nition a superstring of s1 and s2 is one which

  Construct a dfa that recognizes languages

Construct a DFA that recognizes each of the following languages. Unless otherwise noted we are assuming that ω ∈ {0,1}*. (A drawing of a state diagram is sufficient.)

  Modify the syntax of a programming language

Sometimes it is necessary to modify the syntax of a programming language. This is done by changing the CFG that the language uses. What changes would have to be made to ac's CFG (Figure) to implement the following changes?

  Write grammar for language comprising of strings

Write down the grammar for language comprising of strings which have n copies of letter a followed by same number of copies of letter b, where n > 0.

  Write first four strings in lexicographic enumeration

Consider the language L = L1 ∩ L2, where L1 = {ww^R : w ∈ {a, b}* and L2 = {a^n b*a^n: n ≥ 0}. Write the first four strings in the lexicographic enumeration of L?

  Create standard 1-tape turing machine to calculate function

Create a standard 1-tape Turing machine M to calculate the function sub3. Specifically, calculate sub3 of a natural number represented in binary.

  Argue that the problem is np complete

Argue that the following prob is NP Complete. Given list of positive integers, u1,u2,...un (in binary representation) and asked if there is partition of this set into 3 subsets, each of which has same sum.

  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.

  Use undecidability of allcfg to show problem is undecidable

Use undecidability of ALLCFG to illustrate that following problem is also undecidable: Given PDA M1 and FA M2, is L(M1) = L(M2)?

  Cs476 automata theory and formal languages

CS476: Automata Theory and Formal Languages, State whether the following statements are true or not. You must give a BRIEF explanation or show a counter example to receive full credit.

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