Number of sub-sequences in a given sequence

前端 未结 12 621
傲寒
傲寒 2021-01-30 18:18

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

相关标签:
12条回答
  • 2021-01-30 18:37

    Each subsequence is defined by choosing between selecting or not selecting each of the m elements. As there are m elements, each with two possible states, you get 2^m possibilities.

    0 讨论(0)
  • 2021-01-30 18:39

    Each element is either in a subsequence or not. Therefore, starting with the first x1 there are two sets of subsets: those with x1 included and those without. Same can be done with the smaller sub-problem {x2,...,xm}. Therefore you finally yield 2^m.

    0 讨论(0)
  • 2021-01-30 18:43

    If you have a sequence S, what happens when you add a new element x to the end of S?

    All the subsequences of S are still subsequences of your new sequence. So are all those subsequences with x added at the end.

    Voilà! Every time you add an element, you double the number of subsequences.

    0 讨论(0)
  • 2021-01-30 18:45

    Basically you will have twice as many subsequences for each new number since you'll have (2^(m-1)) "equivalent" subsequences that are shifted one space to the right (assuming horizontal ordering and adding in the right) plus the subsequence of all elements.

    0 讨论(0)
  • 2021-01-30 18:46

    For each element in a sequence of length m, you can either select it or leave it. Thus, there are 2 ways to deal with each element. Therefore, the total no. of ways to deal with all the m elements is 2*2*2...... m times = 2^m times.

    0 讨论(0)
  • 2021-01-30 18:47

    To anyone who is actually looking for a substring (as the title or URL might lead you to believe):

    Subset: 2^n (Order doesn't matter in sets)
    Subsequence: 2^n (Since we keep the original ordering, this is the same.)
    Substring: n(n+1) * 1/2 (Elements must be consecutive)
    
    0 讨论(0)
提交回复
热议问题