Question

Consider the following problem: given n positive integers, separate them into two groups such that adding...

Consider the following problem: given n positive integers, separate them into two groups such that adding all the numbers in one group gives the same result as adding all the numbers in the other group. For example, if the numbers are 1, 2, 3, 4, then the two groups could be {1, 4} and {2, 3}, which both sum to 5. For another example, if the numbers are 5, 6, 11, then the two groups could be {5, 6} and {11}. (The groups do not have to be of the same size).

(a) Describe an exhaustive search algorithm for this problem.

(b) What is the asymptotic worst-case running time of your algorithm? Justify your answer.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans 1.

Algo

1. compute total sum of all elements

2. For every item arr[i], we have two choices

    (1) We do not include it first set

    (2) We include it in first set

    We return minimum of two choices

3. If we have reached last element. return two subsets

Ans 2.
All the sums can be generated by either 
(1) including that element in set 1.
(2) without including that element in set 1.
So possible combinations are :-  
arr[0]      (1 or 2)  -> 2 values
arr[1]    (1 or 2)  -> 2 values
.
.
.
arr[n]     (2 or 2)  -> 2 values
So time complexity will be 2*2*..... *2 (For n times),
that is O(2^n).
Add a comment
Know the answer?
Add Answer to:
Consider the following problem: given n positive integers, separate them into two groups such that adding...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Let A be an array containing n numbers (positive and negative). Develop a divide and conquer algo...

    need help in this algorithm question Let A be an array containing n numbers (positive and negative). Develop a divide and conquer algorithm that finds the two indices 1 sisjsn such that A[k] (the sum of the elements from i to j) is maximized. For example, in the array A [10,-5,-6,5, 7,-2,4, -11], the sub-array A[4:6] has the sum 5+ 7-2+4-14 and no other sub-array contains elements that sum to a value greater than 14, so for this input the...

  • 6. Consider the following basic problem. You're given an array A consisting of n integers A[1],...

    6. Consider the following basic problem. You're given an array A consisting of n integers A[1], A[2], , Aln]. You'd like to output a two-dimensional n-by-n array B in which B[i, j] (for i <j) contains the sum of array entries Ali] through Aj]-that is, the sum A[i] Ai 1]+ .. +Alj]. (The value of array entry B[i. Λ is left unspecified whenever i >j, so it doesn't matter what is output for these values.) Here's a simple algorithm to...

  • Consider the following problem: Input: a list of n-1 integers and these integers are in the...

    Consider the following problem: Input: a list of n-1 integers and these integers are in the range of 1 to n. There are no duplicates in list. One of the integers from 1 to n is missing in the list. Output: find the missing integer Let the input array be [2, 4, 1, 6, 3, 7, 8]. Elements in this list are in the range of 1 to 8. There are no duplicates, and 5 is missing. Your algorithm needs...

  • C++ program which partitions n positive integers into two disjoint sets with the same sum. Consider...

    C++ program which partitions n positive integers into two disjoint sets with the same sum. Consider all possible subsets of the input numbers. This is the sample Input 1 6 3 5 20 7 1 14 Output 1 Equal Set: 1 3 7 14 This is the sample Input 2 5 10 8 6 4 2 Output 2 Equal Set: 0

  • Answer B java Problem 2 For each problem given below, do the following: 1. Create an...

    Answer B java Problem 2 For each problem given below, do the following: 1. Create an algorithm in pseudocode to solve the problem. 2.Identify the factors that would influence the running time of your algorithm. For example, if your algorithm is to search an array the factor that influences the running time is the array size. Assign names (such as n) to each factor. 3. Determine the number of operations in each step of the pseudocode. To do that, identify...

  • A problem that can be solved by the Backtracking technique is the 'Sum-of-Subsets' problem. Given n...

    A problem that can be solved by the Backtracking technique is the 'Sum-of-Subsets' problem. Given n distinct positive numbers (usually called weights), we want to find all possible subsets of these numbers whose sum (or weight) is W. A “binary” state space tree (like in the 0/1 Knapsack problem) can be constructed for this problem, where each level represents one of the n numbers. A left branch indicates that the number is included in the subset, and a right branch...

  • Consider the problem where you are given an array of n digits [di] and a positive...

    Consider the problem where you are given an array of n digits [di] and a positive integer b, and you need to compute the value of the number in that base. In general, you need to compute For example: (1011)2 = 1(1) + 1(2) + 0(4) + 1(8) = 11; (1021)3 = 1(1) + 2(3) + 0(9) + 1(27) = 34, and (1023)4 = 3(1) + 2(4) + 0(16) + 1(64) = 75. In these examples, I give the digits...

  • Suppose you are given an array of n integers a1, a2, ..., an. You need to...

    Suppose you are given an array of n integers a1, a2, ..., an. You need to find out the length of its longest sub-array (not necessarily contiguous) such that all elements in the sub-array are sorted in non-decreasing order. For example, the length of longest sub-array for {5, 10, 9, 13, 12, 25, 19, 70} is 6 and one such sub-array is {5, 10, 13, 19, 70}. Note you may have multiple solutions for this case. Use dynamic programming to...

  • Searching/sorting tasks and efficiency analysis - Big-oh For each problem given below, do the following: 1....

    Searching/sorting tasks and efficiency analysis - Big-oh For each problem given below, do the following: 1. Create an algorithm in pseudocode to solve the problem. 2. Identify the factors that would influence the running time of your algorithm. For example, if your algorithm is to search an array the factor that influences the running time is the array size. Assign names (such as n) to each factor. 3. Count the operations performed by the algorithm. Express the count as a...

  • Suppose you are given an array of n integers ai, az, ..., an. You need to...

    Suppose you are given an array of n integers ai, az, ..., an. You need to find out the length of its longest sub-array (not necessarily contiguous) such that all elements in the sub-array are sorted in non-decreasing order. For example, the length of longest sub-array for (5, 10, 9, 13, 12, 25, 19, 30) is 5 and one such sub-array is (5, 10, 13, 19, 303. Note you may have multiple solutions for this case. Use dynamic programming to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT