Recursion- All Subsequences

https://hack.codingblocks.com/practice/p/390/73
This is the question.
This is solution : https://ide.codingblocks.com/#/s/15299
I am unable to do it by recursion .Please give a hint or tell how to approach it.

Everytime you can have two options , either to pik the current current character or leave teh current character , so take an auxilary array and first call the recursion for the next without saving the current charactter in array and second save the current character in array and call the recursion … See this , you will be able to understand
void recursion()
if(s[i]==’\0’){
out[j]=’\0’;
string temp=out;
m[temp]=temp;
//cout<<out<<endl;
return;
}
print_subsequences(s,i+1,out,j,m);
out[j]=s[i];
//cout<<out[j]<<endl;

print_subsequences(s,i+1,out,j+1,m);
1 Like