I have got a pretty hard task I find difficult to handle.
I'm trying to write a recursive function (no loops at all) that, given an array and its length, will print a pair of sub arrays, each of which's sum will be half of the sum of the entire array. In other words, the array is to be divided into two groups of integers so that their sum is equal.
For example, given the array {1,2,2,0,5}, the function should output {1,2,2} {0,5}
I have to do it recursively, with a function that gets only the array itself and its size. I am also only allowed to use one more additional recursive function to solve the problem.
Any thoughts or ideas will be most appreciated.
Hello again! we got a code in class that goes like this
int SubsetSum(int arr[], int idx, int n, int S) {
if (S==0) return 1; //This is stopping condition #1.
if (S<0 || n==0) return 0; //This is stopping condition #2.
return SubsetSum(arr, idx+1, n-1, S-arr[idx]) || SubsetSum(arr, idx+1, n-1, S);
}
what does the " || " operator means in terms of recursion? thanks ppl!