how to find subset of an array using recursion?
How to find subset of an array using recursion?
Hello @pragyachoudhary1111,
You can apply the following logic:
i : refers to the index of the current element
use two recursive statements:
- including the current element in the subset.
- not including the current element in the subset.
For base condition:
when i becomes equal to the length of the set,
check if sum is equal to zero: return true
else return false.
Try to implement this code.
Hope, this would help.
Give a like if you are satisfied.
I have implemented the code for this problem but it is always showing true output. I have not considered the testcases for now
Here is my code-
Hey @pragyachoudhary1111,
There are many mistakes in your code.
I have modified all:
Refer to the comments for better understanding.
Hope, this would help.
Give a like if you are satisfied.
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.