Create all the possible combinations of array a – Software Engineering
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.
📝
Need a custom essay written to your exact brief?
Our PhD-qualified writers craft original, plagiarism-free essays tailored to your topic, word count, citation style, and deadline — argumentative, analytical, descriptive, or reflective. Every paper is 100% written from scratch.
✓ Plagiarism-free · ✓ 100% human-written · ✓ Free revisions · ✓ Confidential
🔒 No payment to start · From $11/page
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.
✍️
Your thesis deserves more than a rushed draft.
Master's and doctoral thesis writing requires a defensible argument, rigorous methodology, and impeccable academic writing. Our thesis specialists have delivered 8,400+ model documents that passed committee review.
✓ Plagiarism-free · ✓ 100% human-written · ✓ Free revisions · ✓ Confidential
🔒 No payment to start · From $11/page
B’= BA, where A = {a1, a2,…….., an} in which AB= b1a1 +b2a2 +……+ bnan. Where ai is either 0 or 1.
📚
Tight deadline? We've handled tighter.
Our fastest writers turn around quality academic work in 3 hours. Full essay, research paper, case study — delivered before your submission time.
24/7 support · No hidden fees
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.