0

Does the recursive code for printing all the subsets of a string and printing all the sub-sequences of a string varies? As we know that sub sequences of a string are part of the subsets of a string for example:

string str="abc";
sub sequences of str : " ", a , b , c , ab , bc , ac , abc;
subsets of str : " ", a , b , c , ab , ba , bc , cb , ca , ac , abc , acb , bac , bca , cab , cba; 
Hemant Rai
  • 31
  • 6
  • Well, if the results are different for the same input, then the code must be different as well. – cigien Aug 16 '20 at 20:41
  • Well, of course you need two different pieces of code in order to produce two different outcomes. I suppose I don't understand the question. – Igor Tandetnik Aug 16 '20 at 20:41
  • Could you quote a definition of your 'subset of a string'? – CiaPan Aug 16 '20 at 20:43
  • How is your question related to C++14, which you indicated with a tag? – CiaPan Aug 16 '20 at 20:44
  • like in many coding platforms they ask to print all the subsets of a string but if i write a recursive code of printing all sub sequences then also complete test cases passes why that?@IgorTandetnik – Hemant Rai Aug 16 '20 at 20:44
  • You are probably misunderstanding the definition of "subset" then. – cigien Aug 16 '20 at 20:46
  • @cigien i have mentioned example above look carefully . – Hemant Rai Aug 16 '20 at 20:48
  • 1
    I see the example. What I mean is, the coding platform's definition might be different from yours, so you should check that first. – cigien Aug 16 '20 at 20:50
  • you're asking if there's a difference, you provide an example showing a difference, but saying a "coding platform" indicates no difference? either the coding platform is wrong, or your understanding is wrong. If you are doing some coding challenge, please provide its description so we can work out which it is. – kmdreko Aug 16 '20 at 20:51
  • ok i got you @cigien . I think that there will be huge size and numbers of the test cases if they ask to print all of the subsets of a string that's why they restrict us to print sub sequences. – Hemant Rai Aug 16 '20 at 20:57
  • How is `ac` a subsequence of `abc`? – Ted Hopp Aug 16 '20 at 20:59
  • @TedHopp check definition of subsequence . A subsequence can be discontinuous but order have to be preserved. i.e., "ab" and "ac" are subsequences of "abc" but "ba" and "ca" cannot be its subsequence. – Hemant Rai Aug 16 '20 at 21:03

1 Answers1

0

Subsequence refers to you have to pick elements in sequence (moving forward).

str = "abc"

pick 'a'
pick 'c'
as you picked 'c', you cant pick 'b' as it is present backwards of 'c'.

In subsets, you can use ay combination of characters

str = "abc"

pick 'a'
pick 'c'
you can pick 'b' as well, even though it is at previous position than 'c'

another_CS_guy
  • 682
  • 6
  • 7