# Computer science assessment subset-sum problem

**9) 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,….., bnand 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, ……, bnanwhen 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.

**10) 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.

## We've got everything to become your favourite writing service

### Money back guarantee

Your money is safe. Even if we fail to satisfy your expectations, you can always request a refund and get your money back.

### Confidentiality

We don’t share your private information with anyone. What happens on our website stays on our website.

### Our service is legit

We provide you with a sample paper on the topic you need, and this kind of academic assistance is perfectly legitimate.

### Get a plagiarism-free paper

We check every paper with our plagiarism-detection software, so you get a unique paper written for your particular purposes.

### We can help with urgent tasks

Need a paper tomorrow? We can write it even while you’re sleeping. Place an order now and get your paper in 8 hours.

### Pay a fair price

Our prices depend on urgency. If you want a cheap essay, place your order in advance. Our prices start from $11 per page.