Hướng dẫn subset sum problem python dynamic programming - bài toán tổng tập con python lập trình động
Cho một tập hợp các số nguyên không âm và tổng giá trị, xác định xem có một tập hợp con của tập hợp đã cho với tổng bằng với tổng đã cho. & NBSP; Show
Example: Input: set[] = {3, 34, 4, 12, 5, 2}, sum = 9 Output: True There is a subset (4, 5) with sum 9. Input: set[] = {3, 34, 4, 12, 5, 2}, sum = 30 Output: False There is no subset that add up to 30. Phương pháp 1: đệ quy.Approach: Đối với phương pháp đệ quy, chúng tôi sẽ xem xét hai trường hợp. & Nbsp; Recursion.
Sau đây là công thức đệ quy cho vấn đề ISSUBSETSUM (). & NBSP; isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0 Chúng ta hãy xem xét mô phỏng của cách tiếp cận ở trên-: & nbsp; set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False} C++
isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 00 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 01 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 04 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 06 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 08 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}2 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}9 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 Found a subset with given sum2 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 Found a subset with given sum6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 Found a subset with given sum9 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]2 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]4 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]7 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T9 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8 Found a subset with given sum1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____21 Found a subset with given sum4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 Found a subset with given sum6 Found a subset with given sum7 Found a subset with given sum8 Found a subset with given sum9 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 #include 2set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum8 #include 5set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 #include 9if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 C
isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 01 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 04 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 06 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 08 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}2 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}9 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 Found a subset with given sum2 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 Found a subset with given sum6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 Found a subset with given sum9 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]2 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]4 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]7 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T9 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8 Found a subset with given sum1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____21 Found a subset with given sum4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 Found a subset with given sum6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 039 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 Found a subset with given sum9 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 #include 2set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 039 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 #include 5isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 #include 9if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 Cset[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]2 Java isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 054 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 055 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 058 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 061 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 062 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 06 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 08 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 071 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 Found a subset with given sum6 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 080 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 Found a subset with given sum6 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 Found a subset with given sum2 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 089 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 091 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}05 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}07 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 094 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 096 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 094 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}01 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}11 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}13 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}14 Các set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}34 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}35 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}46 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}47 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 062 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}49 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}50 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 #include 2isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}46 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}56 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 062 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}49 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}59 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 094 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 096 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 Python3set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 094 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}01 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}11 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}13 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}14 Các set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}34 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}35 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}39 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 Found a subset with given sum4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 Found a subset with given sum6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}64 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}67 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}68 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}69 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}68 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}74 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}74 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 Found a subset with given sum16 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}96 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}21 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}68 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}96 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 Found a subset with given sum33 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}96 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 Found a subset with given sum36 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}80 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____21 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}83 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}74 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}74 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}69 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}90 Các set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum72 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 Found a subset with given sum9 Found a subset with given sum6
Found a subset with given sum77 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum72 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 #include 5Found a subset with given sum6 C#
Found a subset with given sum84 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 054 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 055 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 01 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum92 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}2 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}9 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 Found a subset with given sum2 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]19 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]24 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]29 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]30 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]31 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]33 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]35 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____211 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}13 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]42 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum92 ____266 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]49 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]57 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 Found a subset with given sum62 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]62 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 Found a subset with given sum6 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]66 Found a subset with given sum9 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 #include 2isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]66 #include 5isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 PHPif (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]78 Is isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____21 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]92 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]95 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____21 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]92 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T03 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 Found a subset with given sum39 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T10 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85 Found a subset with given sum6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}21 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T19 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85__ set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}21 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T19 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T30 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}21 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T36 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T37 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T39 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 Found a subset with given sum39 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T43 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T46 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T47 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T48 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T50 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T52 Is set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T62 Found a subset with given sum9 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6
set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T62 #include 5set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T70 JavaScriptset[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T71 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]79 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T74 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}2 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}9 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 Found a subset with given sum2 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]19 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]24 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]29 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]30 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum05 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum07 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____211 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}13 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]42 Found a subset with given sum15 Found a subset with given sum16 Found a subset with given sum9 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 #include 2Found a subset with given sum15 Found a subset with given sum16 #include 5isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 Found a subset with given sum25
Found a subset with given sum
if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]
Is set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____21 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]92 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False} 3set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False} 4 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]95
set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____21 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]92 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T03 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 Found a subset with given sum39 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T10 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85 Found a subset with given sum6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum45 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}21 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T19 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85__ set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum54 Found a subset with given sum2 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}21 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T19 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T30 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}21 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T36 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T37 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T39 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 Found a subset with given sum39 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T43 Found a subset with given sum70 Found a subset with given sum71 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T46 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T47 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T48 Found a subset with given sum70 Found a subset with given sum76 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 062 Found a subset with given sum78 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T50 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T52 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 Is set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T9 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8 Found a subset with given sum1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____21 Found a subset with given sum4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 Found a subset with given sum6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 039 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 Found a subset with given sum9 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 #include 2set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 039 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 #include 5isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 #include 9if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 C++
isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 00 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 01 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 04 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 06 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 08 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 01 Found a subset with given sum38 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum43 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum45 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum52 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum54 Found a subset with given sum2 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum61 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum66 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 Found a subset with given sum69 Found a subset with given sum70 Found a subset with given sum71 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 Found a subset with given sum74 Found a subset with given sum70 Found a subset with given sum76 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 062 Found a subset with given sum78 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 Found a subset with given sum85 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]7 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T9 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8 Found a subset with given sum1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____21 Found a subset with given sum4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 Found a subset with given sum6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 #include 9set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 #include 2set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum8 #include 5set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 #include 9if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 using namespace isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0 0isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 01 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 04 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 06 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 08 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 01 Found a subset with given sum38 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum43 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum52 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum61 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum66 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 Found a subset with given sum69 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 using 69isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 using 71Found a subset with given sum2 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 Found a subset with given sum74 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 Found a subset with given sum85 Found a subset with given sum70 using 89isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 using 47isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]7 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T37 using 98
isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 namespace 02isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 using 47isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum8 Found a subset with given sum9 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 Java set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 054 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 055 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 058 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 061 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 062 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 06 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 08 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 058 using 40using 41 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 058__ isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}46 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}47 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 062 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}49 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}50 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 #include 2isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}46 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}56 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 062 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}49 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}59 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum8 Found a subset with given sum9 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 Python3Java isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 054 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 055 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 058 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 061 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 062 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 06 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 08 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 058 using 40using 41 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 058__ set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 using 52isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 using 54isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 using 56isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 using 58set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 using 52isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 using 67set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 using 52isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 using 80isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 using 85isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 using 87Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 using 94isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 Found a subset with given sum36 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 namespace 11set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}11 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}13 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}14 Các set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}34 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}35 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}74 Found a subset with given sum39 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}20 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}21 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}2222221 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}24 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}21 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}26____221 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}28 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}21__ set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}68 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}74 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}35 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum55 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}74 Found a subset with given sum57 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}666____66 Is set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum72 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 Found a subset with given sum9 Found a subset with given sum6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 #include 2Found a subset with given sum77 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum72 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 #include 5Found a subset with given sum6 C#
Found a subset with given sum84 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 054 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 055 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 01 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum92 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 01____1178 using 41 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 01 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0181 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum43 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0188 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum52 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0197 Found a subset with given sum2 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0204 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0209 Found a subset with given sum70 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0211 Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0214 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0216 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T37 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0218
isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0220 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0222 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0229 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____211 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}13 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]42 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum92 ____266 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]49 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]57 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 Found a subset with given sum62 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}66 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]62 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 Found a subset with given sum6 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]66 Found a subset with given sum9 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 #include 2isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]66 #include 5isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 PHPif (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]78 Is isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0283 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T46 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T47 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T47 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0288 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0291 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0293 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0283 Found a subset with given sum39 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0304 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0291 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0309 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0283 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0318 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 02929____1320 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0309 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0295__ set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0337 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0309 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0337 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0295__ set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 Các Found a subset with given sum70 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0283 Found a subset with given sum39 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0360 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0337 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0362 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0363 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0283 Found a subset with given sum39 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0367 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0337 using 47isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0337 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0374 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 Found a subset with given sum39 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 Found a subset with given sum70 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0283 Found a subset with given sum39 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0360 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0337 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0362 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0386 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0283 Found a subset with given sum39 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0367 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0337 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0392 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0386 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0283 Found a subset with given sum39 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0397 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0337 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0399 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 062 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 Found a subset with given sum39 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0292 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0404 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0283 Found a subset with given sum39 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0360 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85 using 47if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T46 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T47 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T48 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T50 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T46 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0426 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 Is set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T62 Found a subset with given sum9 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6
set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T62 #include 5set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T70 JavaScriptset[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T71 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]79 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T74 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0455 using 41 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0457 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0460 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0464 using 41 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0457 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0469 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 Found a subset with given sum70 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0473 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0480 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 Found a subset with given sum54 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0487 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 Found a subset with given sum45 Found a subset with given sum2 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0494 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0497 Found a subset with given sum70 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0499 Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0502 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T37 using 98
isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0506 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 namespace 11set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum05 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum07 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____21 Found a subset with given sum4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}5 Found a subset with given sum6 Found a subset with given sum15 Found a subset with given sum16 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}47 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}49 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}50 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 #include 2Found a subset with given sum15 Found a subset with given sum16 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}56 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}49 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}59 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 Found a subset with given sum25 Đầu ra Found a subset with given sum Phân tích độ phức tạp: Độ phức tạp về thời gian: O (tổng*n), trong đó tổng là 'tổng mục tiêu' và 'n' là kích thước của không gian mảng . + O (n) cho không gian ngăn xếp đệ quy O(sum*n), where sum is the ‘target sum’ and ‘n’ is the size of
array. Kỹ thuật ghi nhớ để tìm tập hợp con: Method:
Dưới đây là việc thực hiện phương pháp trên: C++isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0542
isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 00 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0547 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0549 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0551 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 06 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}2 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0562 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____21 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0565 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 #include 9set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____21 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0571 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0574 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____21 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0577 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0580 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 #include 2set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0587 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0386 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0589 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]7 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0597 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0598 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0600 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0603 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0606 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0609 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0__21 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0612 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0616 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0617 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0618 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 #include 2set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0616 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0625 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0618 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 JavaisSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 054 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 055 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0549 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 06444 using 41 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0647 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0649 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 using 47set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 using 52isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0658 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 using 85isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0665 Found a subset with given sum70 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0667 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 071 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 Found a subset with given sum6 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0685 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 Found a subset with given sum6 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0694 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0696 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 Found a subset with given sum6 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0701 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0703 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0706 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 091 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0701 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0713 Found a subset with given sum70 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0715 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 096 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 #include 2 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0723 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0725 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 Found a subset with given sum70 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0728 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0730 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 Found a subset with given sum36 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0386 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0734 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0736 Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0701 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0741 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 #include 2Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0701 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0741 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0____211 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}13 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0763 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}28 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 Các set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}34 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}26 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}6 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0791 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0736 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}46 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0796 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 #include 2isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}46 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0804 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 Python3isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0809 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}74 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0811 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}96 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 Found a subset with given sum40 namespace 80__set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}64 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0829 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}68 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}69 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}68 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}74 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}74 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0__21 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0845 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}74 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}69 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 072 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0854 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}96 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090__ set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0866 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}96 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0360 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}68 Found a subset with given sum51 Is set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0866 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}96 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090__ set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0866 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}96 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0360 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}68 Found a subset with given sum51 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 #include 2Found a subset with given sum77 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0866 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}96 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090__ set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0866 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}96 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 090__ Found a subset with given sum55 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}74 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}28 Các set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}68 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}74 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}26 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0958 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}68 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0960 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum72 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0617 Found a subset with given sum6
Found a subset with given sum77 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 Found a subset with given sum72 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0625 Found a subset with given sum6 C#
Found a subset with given sum84 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 054 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0976 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0549 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0983__ set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0992 using 41 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0995 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum61 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 Found a subset with given sum40 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 040 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 Found a subset with given sum66 Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}007 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}2 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0562 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0565 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 #include 9set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}026 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}029 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0577 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}035 Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}037 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 #include 2 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}043 Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}045 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0386 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}047 Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}050 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 #include 2Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}057 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}11 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 057 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}13 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}066 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0603 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0609 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}080 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}082 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0796 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 #include 2isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}082 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0804 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}0 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 JavaScriptset[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T71 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]79 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}099 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}2 Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0562 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0565 Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 #include 9isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0571 Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0574 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0577 Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0580 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 #include 2 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 Found a subset with given sum70 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}4 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}129 set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T37 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0589 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}137 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}139 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}141 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}143 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}146 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 Found a subset with given sum16 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0617 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}49 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}151 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 042 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 #include 2 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 09 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 074 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}1 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}043 set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5 Found a subset with given sum25
set[]={3, 4, 5, 2} sum=9 (x, y)= 'x' is the left number of elements, 'y' is the required sum (4, 9) {True} / \ (3, 6) (3, 9) / \ / \ (2, 2) (2, 6) (2, 5) (2, 9) {True} / \ (1, -3) (1, 2) {False} {True} / \ (0, 0) (0, 2) {True} {False}3 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 03 isSubsetSum(set, n, sum) = isSubsetSum(set, n-1, sum) || isSubsetSum(set, n-1, sum-set[n-1]) Base Cases: isSubsetSum(set, n, sum) = false, if sum > 0 and n == 0 isSubsetSum(set, n, sum) = true, if sum == 0603 Perfect Sum Problem (Print all subsets with given sum) Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. Là tập hợp con vấn đề lập trình động?Có, SUBS-SUM là một vấn đề tối ưu hóa vì nó có nhiều thuật toán để giải quyết nó. Làm thế nào để bạn giải quyết các tập hợp con? Các tập hợp con có thể được giải quyết bằng cách sử dụng chương trình quay lại và lập trình động với độ phức tạp thời gian hiệu quả.Subsets can be solved using backtracking and dynamic programming with efficient time complexity.
Độ phức tạp về thời gian của giải pháp lập trình động của tổng số tập hợp con được cho tổng hợp tập con) là gì?Giải thích: Vấn đề tổng hợp tập con có cả giải pháp lập trình đệ quy cũng như động.Giải pháp lập trình động có độ phức tạp về thời gian của O (n*sum) vì nó là một vòng lặp lồng nhau với các giới hạn từ 1 đến N và 1 đến tổng tương ứng.O(n*sum) as it as a nested loop with limits from 1 to n and 1 to sum respectively.
Tổng số vấn đề tập hợp con giải thích với ví dụ là gì?Vấn đề về tổng tập hợp con liên quan đến việc xác định xem một tập hợp con từ danh sách các số nguyên có thể tổng hợp với giá trị mục tiêu hay không.Ví dụ: hãy xem xét danh sách NUMS = [1, 2, 3, 4].Nếu Target = 7, có hai tập con đạt được tổng này: {3, 4} và {1, 2, 4}.Nếu Target = 11, không có giải pháp.determining whether or not a subset from a list of integers can sum to a target value. For example, consider the list of nums = [1, 2, 3, 4] . If the target = 7 , there are two subsets that achieve this sum: {3, 4} and {1, 2, 4} . If target = 11 , there are no solutions.
Vấn đề tổng hợp tập con trong cấu trúc dữ liệu là gì?Vấn đề tổng hợp tập con là tìm tập hợp con của các phần tử được chọn từ một tập hợp nhất định có tổng cộng với một số nhất định K. Chúng tôi đang xem xét tập hợp chứa các giá trị không âm.Giả định rằng bộ đầu vào là duy nhất (không có bản sao được trình bày).to find subset of elements that are selected from a given set whose sum adds up to a given number K. We are considering the set contains non-negative values. It is assumed that the input set is unique (no duplicates are presented). |