Create all the possible combinations of array a

Assignment Help Data Structure & Algorithms
Reference no: EM13309935

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.

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

Questions Cloud

Obtain the current in the inductor : An inductor has an inductance of 0.069 H. The voltage across this inductor is 56 V, What is the current in the inductor
What shape and distribution of mass should it have : To maximize the moment of inertia of a flywheel while minimizing its weight, what shape and distribution of mass should it have
Determine the ionization energy of hydrogen : Determine the ionization energy of hydrogen if the shortest wavelength in the Balmer series is found to be 3650 AO
A variable cross section data taken at two axial positions : An aqueous solution with a specific gravity of 1.12 flows through a channel with a variable cross section, data taken at two axial positions in the channel are shown here. Point 2 is 6.00 meters higher than point 1.
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..
How large an expansion tank do you specify : Fuel systems of modern cars are designed so thermal expansion of gasoline doesn't result in wasteful and polluting fuel spills. How large an expansion tank do you specify
Determine force exerted by the hydraulic cylinder on boom : A hoist mechanism is attached to the back of a pickup truck. The crate being moved by the hoist shown below weighs 200 lbs. Note: Point A is directly above point B and the vertical distance between points A and B is 16 inches.
Evaluate the equilibrium partial pressures of c2h6 : Calculate the equilibrium partial pressures of C2H6, N2, NH3, and C2H4. Peq(C2H6) = . Peq(N2) = . Peq(NH3) = . Peq(C2H4) = . (b) Calculate KP for this reaction. KP =.
At what distance from bottom of the hill did the car stop : on a windy day, a person on a cart (combined mass m of 70kg) begins at the top of a hill 10m hihg traveling at 3m/s, At what distance from the bottom of the hill did the car stop

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Write a procedure hamming

Write a procedure hamming(ascii, encoded) that converts the low-order 7 bits of ascii into an 11-bit integer codeword stored in encoded.

  Write algorithm segment for locating nth successor of item

Write an algorithm or code segment for locating the nth successor of an item in a circlar linked list (the nth item that follows the given item in the list).

  Spreadsheet to compute projected total costs and profits

Prepare a spreadsheet to compute your projected total costs, total revenues, and total profits for giving seminar on cost estimating.

  How two types of assets are valued for balance sheet purpose

Explain how the 2-types of assets are valued for balance sheet purposes, using the following assets owned by a corporation that writes and sells software packages

  Creating an effective physical design

Class, do IT database designers necessary to understand data volumes and number of users of database in order to create an effective physical design?

  Find values of n insertion sort beat merge sort

For inputs of size n, insertion sort runs in 8n 2 steps, where as merge sort runs in 64* nlog base 2 n steps. For which values of n odes insertion sort beat merge sort?

  Determine algorithm for cs curriculum consists of n courses

Determine an algorithm which works directly with this graph representation, and calculates minimum number of semesters necessary to complete the curriculum.

  A and b, both of which perform the same function

Assume you have two algorithms, A and B, both of which perform the same function,

  Find maximum possible amount of money by optimal strategy

Removes it from row permanently, and receives value of coin. Find out the maximum possible amount of money we can definitely win if we move first.

  Algorithm on dynamic programming-minimize amount of walking

Our goal is to plan this trip so that we minimize the maximum amount of walking done in a single day. Your algorithm should be based on dynamic programming and run efficiently.

  Exhibit an algorithm that detects automation

Exhibit an algorithm that detects whether one finite automaton accepts a subset of the set accepted by another machine.

  Creating dataflow diagram

Think about the level of detail involved with creating a dataflow diagram, why should the narrative be prepared? Explain why do we need the questionnaire?

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