diff --git a/Power Set: Print all the possible subsequences of the String b/Power Set: Print all the possible subsequences of the String new file mode 100644 index 0000000..7ea1257 --- /dev/null +++ b/Power Set: Print all the possible subsequences of the String @@ -0,0 +1,78 @@ +Problem Statement: Given a string, find all the possible subsequences of the string. + +APPROACH 1 + +#include +using namespace std; +vector AllPossibleStrings(string s) { + int n = s.length(); + vectorans; + for (int num = 0; num < (1 << n); num++) { + string sub = ""; + for (int i = 0; i < n; i++) { + //check if the ith bit is set or not + if (num & (1 << i)) { + sub += s[i]; + } + } + if (sub.length() > 0) { + ans.push_back(sub); + } + } + sort(ans.begin(), ans.end()); + return ans; +} +int main() +{ + + + string s="abc"; + vectorans = AllPossibleStrings(s); + //printint all the subsequence. + cout<<"All possible subsequences are "< +using namespace std; +void solve(int i, string s, string &f) { + if (i == s.length()) { + cout << f << " "; + return; + } + //picking + f = f + s[i]; + solve(i + 1, s, f); + //poping out while backtracking + f.pop_back(); + solve(i + 1, s, f); +} +int main() { + string s = "abc"; + string f = ""; + cout<<"All possible subsequences are: "<