what both the for loops are doing ?
whats the need ?
what both the for loops are doing ?
whats the need ?
Hi,
There are 2^n subsequences possible in given array of size n. Now, binary representation of each number from 1 to 2^n-1 if we take the number from the positions where set bit is present then we can get all possible subsequences. First for loop does this thing. And second for loop is used to take those elements where set bits are present.
i dont understand anything. can u explain me with example ?
Consider binary representation from 1 to 3:
01
10
11
Consider a string:“ab”
the subsequences of ab are: a,b,ab.
we can get a by using binary representation of 1.
we can get b by using binary representation of 2.
we can get ab by using binary representation of 3.