Sybsetsumcpp dry run

code 1:-https://ide.codingblocks.com/s/199819

code 2:- https://ide.codingblocks.com/s/199582
plz dry run both the codes and clarify the doubt which is written in code 1.

Hi @Kush_1312

The doubt you mentioned in code 1 is right. The sum+=a[i] line is executed after the recursive call above it reaches base case. Both the code are right and will give correct answer. Just change a[i]==’\0’ condition to i==n by declaring n global or passing it as parameter.

hope it helps.

could you plz provide me with the dry run?

plz could you plz dry run both the codes??

both are nearly same codes, I will dry run code 1 for you. Similarly you can approach the second code.
intitially let eg be : 1 2 3 9 -2 -3 5 . First we pass array, starting index, sum and total number of subset that give sum 0. In each call, it checks if we have reached end of array for a particular starting array index. If we have, then we check if sum is 0 or not and then update the count accordingly. In 2 recursive calls, we first have call 1 which doesn’t take into account the current element in sum and recursively call for other elements. In second call we take into account the current element and recursively call the solve function for the leftover elements.

Hope it Helps.

@Kush_1312
Please mark your doubt as solved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.