abo.bakr's blog

By abo.bakr, history, 2 years ago, In English

A language L consists of the words {01, 111, 1001, 0011}. The language L ∗ is formed by all possible concatenations of the words in the language L. Which one of the following words belongs to the language L ∗?

  • Vote: I like it
  • -18
  • Vote: I do not like it

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I guess you forgot to give the "following words" :)

»
2 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

you need to try concatenations all possible words from L

that means you need to Generating all possible Subsequences

read this blog to know how to do that https://www.geeksforgeeks.org/generating-all-possible-subsequences-using-recursion/

after that check the following words **[I think it's from input as I guess] if it included on it.

  • »
    »
    2 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    to it's look like this

    vector<string>ans;
    // Recursive function to print all
    // possible subsequences for given array
    void printSubsequences(string arr[], int index,
                           vector<string> subarr,int n)
    {
        // Print the subsequence when reach
        // the leaf of recursion tree
        if (index == n)
        {
            string s = "";
            for (auto it:subarr){
                s += it;
            }
            ans.push_back(s);
            return;
    
        }
        else
        {
           //pick the current index into the subsequence.
            subarr.push_back(arr[index]);
           
     
             printSubsequences(arr, index + 1, subarr,n);
     
             
            subarr.pop_back();
           
          //not picking the element into the subsequence.
            printSubsequences(arr, index + 1, subarr,n);
        }
        
    }
    int main()
    {
    
        string arr[]={"01", "111", "1001", "0011"};
        int n=4;
        vector<string> vec;
        printSubsequences(arr, 0, vec,n);
    
        // check here
        for(auto i : ans){
            cout<<i<<" ";
        }cout<<endl;
    
        return 0;
    }
    
  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you a lot