Question: 2 (15 points) In this problem, you are given a list of numbers l: [l[0], ..., l[n-1]]. Your goal is to partition this into two

2 (15 points) In this problem, you are given a list of numbers l: [l[0], ..., l[n-1]]. Your goal is to partition this into two lists l1, l2 such that each element l[i] belongs to exactly one of l1, l2 and the difference between the sums of the two lists is minimized: min |sum()sum()| where sum() for a list denotes the sum of the elements in a list. Example l = [ 1, 5, 7, 8, 4, 6, 15] Partition it as l1 = [1, 7, 15], l2 = [5, 8, 4, 6] Note that in this case sum(l1) = sum(l2) = 23. Thus, we have minimized the absolute difference to 0, which is the best possible. Dynamic Programming Let (,1,2) denote the minimum difference achievable when considering the sublist [l[i],...,l[n-1]] with 1 being the sum of elements already committed to list l1 and 2 being the sum of elements already committed to l2. (,1,2)={???min((+1,???,2),(+1,1,???)) sublist is empty1 assign l[i] to l1 or l2 Implement the function computeBestPartition(l) that takes in a list l and returns the partition as a tuple of lists (l1, l2). Assume that all elements of the list l are positive whole numbers. Complete and memoize the recurrence above. Recover the solution def computeBestPartition(l): n = len(l) assert n >= 1 assert all(elt >= 1 and elt== int(elt) for elt in l) in python code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!