If I am given a sequence X = {x1,x2,....xm}
, then I will have (2^m)
subsequences. Can anyone please explain how can I arrive at this formula intuitively? I can start with 3 elements, then 4 and then 5 and arrive to this formula, but I don't think I understand. Where did the '2' come from? I am not dividing in half or anything here. Thank-you for the help.
Given a string, find the count of distinct subsequences of it. The problem of counting distinct subsequences is easy if all characters of input string are distinct. The count is equal to nC0 + nC1 + nC2 + … nCn = 2n.
@RossMillikan So the total number of subsequences in a string is 2n, where n is the length of the string.
A subsequence of a string is a sequence that can be derived from the given string by deleting zero or more elements without changing the order of the remaining elements.
Given an array arr[]and an integer K, the task is to find the sum of all K length subsequences from the given array. Explanation: There are 6 subsequences of length 2 which are {7, 8}, {7, 9}, {7, 2}, {8, 9}, {8, 2} and {9, 2}.
First of all, what you are talking about is called a set. Second, it is correct that the number of distinct sub-sets that can be generated out of a set is equal to 2^m where m is the number of elements in that set. We can arrive at this result if we take an example of 3 elements:
S = {a, b, c}
Now to generate every sub-set we can model the presence of an element using a binary digit:
xxx where x is either 0 or 1
Now lets enumerate all possibilities:
000 // empty sub-set 001 010 011 100 101 110 111 // the original set it self!
Lets take 011
as an example. The first digit is 0 then, a
is not in this subset, but b
and c
do exist because their respective binary digits are 1's. Now, given m(e.g 3 in the above example) binary digits, how many binary numbers(sub-sets) can be generated? You should answer this question by now ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With