0

I have tried a approach of print all the subsequences of a stirng using recursion but not able to implement this how can i print all the subsequences of a string in lexicographical order. INPUT:- abc OUTPUT: a b c ab ac bc abc

I have tried this approach to print all the subsequences of a string:

void print(string s,string temp)
{
    if(s.empty()){
        cout<<temp<<endl;
        return;
    }
    print(s.substr(1),temp + s[0]);
    print(s.substr(1),temp);
}
John Kugelman
  • 349,597
  • 67
  • 533
  • 578

1 Answers1

0

What you want to have is a so called power set. Please read here about that.

There are som many examples for recursive approaches, that I will not show my onw solution. Maybe best for you would be:

this

And, if you want to have a little bit more background information then please look here

A M
  • 14,694
  • 5
  • 19
  • 44