Closed 2devyank closed 3 years ago
@SarthakKeshari please assign me this issue
@2devyank, Kindly elaborate in comments that how you are going to approach this problem.
@SarthakKeshari
Generate Power set using Bitwise operator
Input="ab" Output="","a","b","ab"
Basically what we have to do is check whether a bit is set or not if a bit is set then will print that character
So if n is the length of string given , then the number of subsets of that string is 2^n. Therefore ,will be running two loop firstly will run the outer loop from 0 to (2^n)-1 and inside will run loop of the length of string and will check using bitwise operator if a bit is set or not ,if bit is set then will print that character
@SarthakKeshari
Question
Generate Power set using Bitwise operator
Sample Case
Input="ab" Output="","a","b","ab"
Approach
Basically what we have to do is check whether a bit is set or not if a bit is set then will print that character
So if n is the length of string given , then the number of subsets of that string is 2^n. Therefore ,will be running two loop firstly will run the outer loop from 0 to (2^n)-1 and inside will run loop of the length of string and will check using bitwise operator if a bit is set or not ,if bit is set then will print that character
@2devyank, Good to see a different approach. I appreciate your thought out of the box against the general trend of just using string handling for every string question.
Enter your question -
Generate Power set using Bitwise operator Input="abc". output="","a","b","c","ac","ab","bc","abc".
Bit-manipulation