(arr)
| 2 | Partition a set into two subsets such that the difference of subset sums is minimum |
| 3 | """ |
| 4 | def findMin(arr): |
| 5 | n = len(arr) |
| 6 | s = sum(arr) |
| 7 | |
| 8 | dp = [[False for x in range(s+1)]for y in range(n+1)] |
| 9 | |
| 10 | for i in range(1, n+1): |
| 11 | dp[i][0] = True |
| 12 | |
| 13 | for i in range(1, s+1): |
| 14 | dp[0][i] = False |
| 15 | |
| 16 | for i in range(1, n+1): |
| 17 | for j in range(1, s+1): |
| 18 | dp[i][j]= dp[i][j-1] |
| 19 | |
| 20 | if (arr[i-1] <= j): |
| 21 | dp[i][j] = dp[i][j] or dp[i-1][j-arr[i-1]] |
| 22 | |
| 23 | for j in range(int(s/2), -1, -1): |
| 24 | if dp[n][j] == True: |
| 25 | diff = s-2*j |
| 26 | break; |
| 27 | |
| 28 | return diff |
nothing calls this directly
no outgoing calls
no test coverage detected