I am learning recursion and having hard time in tracing recursion.
Here is my problem and I have the solution which is working perfectly fine.
I am stuck at some point and not able to proceed with tracing.
problem:
Given an array of ints, is it possible to choose a group of some of the ints, such that the group sums to the given target.
Solution:
public static boolean groupSum1(int start, int[] nums, int target)
{
if (start >= nums.length) return (target == 0);
if (groupSum1(start + 1, nums, target - nums[start])) return true;
if (groupSum1(start + 1, nums, target)) return true;
return false;
}
start = 0 (where we have to start the array)
nums[]={10,8,6} target = 16
Please help me with tracing of the problem?
Start by numbering the lines
Here’s the execution (assuming this is what you are asking for):
The number in front of the recursive call is just an index I’m using to keep track of depth. I hope it’s understandable.