@@ -0,0 +1,1042 @@
+%0A%0Adef findMinRec(arr, i, sumCalculated,%0A%09%09%09sumTotal):%0A%0A%09# If we have reached last element.%0A%09# Sum of one subset is sumCalculated,%0A%09# sum of other subset is sumTotal-%0A%09# sumCalculated. Return absolute%0A%09# difference of two sums.%0A%09if (i == 0):%0A%09%09return abs((sumTotal - sumCalculated) -%0A%09%09%09%09sumCalculated)%0A%0A%09# For every item arr%5Bi%5D, we have two choices%0A%09# (1) We do not include it first set%0A%09# (2) We include it in first set%0A%09# We return minimum of two choices%0A%09return min(findMinRec(arr, i - 1,%0A%09%09%09%09%09%09sumCalculated+arr%5Bi - 1%5D,%0A%09%09%09%09%09%09sumTotal),%0A%09%09%09findMinRec(arr, i - 1,%0A%09%09%09%09%09%09sumCalculated, sumTotal))%0A%0A# Returns minimum possible%0A# difference between sums%0A# of two subsets%0A%0A%0Adef findMin(arr, n):%0A%0A%09# Compute total sum%0A%09# of elements%0A%09sumTotal = 0%0A%09for i in range(n):%0A%09%09sumTotal += arr%5Bi%5D%0A%0A%09# Compute result using%0A%09# recursive function%0A%09return findMinRec(arr, n,%0A%09%09%09%09%090, sumTotal)%0A%0A%0A# Driver code%0Aif __name__ == %22__main__%22:%0A%0A%09arr = %5B3, 1, 4, 2, 2, 1%5D%0A%09n = len(arr)%0A%09print(%22The minimum difference %22 +%0A%09%09%22between two sets is %22,%0A%09%09findMin(arr, n))%0A%0A

Partition a set into two subsets such that the difference of subset sums is minimum