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 intuitivel
To extend the accepted answer, the number of subsequences can be thought in mathematical terms. Let's take an example of a string: 'ABC'.
Number of subsequences of string 'ABC':
=> C(3, 0) + C(3, 1) + C(3, 2) + C(3, 3) = 1 + 3 + 3 + 1 = 8 (2^3).
(Note: C(m, n) stands for number of subsequences of size 'n' from a string of size 'm')
It can be easily verified by listing all of them:
C(3, 0) = '', // Taking 0 letters at a time out of the given string.
C(3, 1) = 'A', 'B', 'C', // Taking 1 letter at a time.
C(3, 2) = 'AB', 'AC', 'BC', // Taking 2 letters at a time.
C(3, 3) = 'ABC'. // Taking 3 letters at a time.
(Total count = 8)
We keep the sequence of letters same for a subsequence, hence, Combination instead of a Permutation.
Note: Sum of binomial coefficients, using binomial theorem = 2^n. Proof below:
From Binomial theorem,
(x + y)^n = C(n, 0) x^n y^0 + .... + C(n, n) x^0 y^n
Using x = 1, y = 1,
(1+1)^n = C(n, 0) 1^n 1^0 + .... + C(n, n) 1^0 1^n
=> 2^n = C(n,0) + C(n,1) + .... + C(n,n)
That's where the '2' comes from, from binomial theorem.
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 ;)
For any sequence X = {x1,x2,....xm}, there will be (2^m) sub-sequences, because you can "choose" sub-sequences of length 0,1,2,...,m ,i.e., mathematically it is
"C(m,0) + C(m,1) + ... C(m,m)" which leads to 2^m.
For e.g., say the string is "abc", then
C(3,0) = 1, ""
C(3,1) = 3, "a", "b", "c"
C(3,2) = 3, "ab", "bc", "ac"
C(3,3) = 1, "abc"
number of subsequences are 8 i.e., 2^3.
For more details visit http://en.wikipedia.org/wiki/Binomial_coefficient#Series_involving_binomial_coefficients
I started algorithm course very recently.
I guess the more intuitive way of thinking about the answer is to think of an example.
For example, we have A=(1,2,3) Then we may have 0 that's 1 way 1,2 or 3 that's 3 ways (1,2),(1,3),(2,3) that's 3 ways as well And (1,2,3) == that's 1 way again
Total subsequence is 2^3 or 8. So the Generic formula is mC0+mC1+mC2,mC3+......mCm
Please correct me if I'm wrong. I faced this problem minutes ago and this is how I thought about the intuitive formulation.
The value x_i
can either be in the subsequence, or not. This is just like a bit. There are 2^m
combinations for turning on / turning off the m
numbers in the sequence.
Where did the 2 come from? Every time you add one more element you double the number of possibilities.