permutation with restriction

A subsequence of a word is obtained by dropping some letters from it. The letters that are dropped need not be consecutive. For instance, ba, bna and banaa are all sub-sequences of the word banana.

We are interested in counting the number of distinct sub-sequences of a fixed length of a given word. For example, the word banana has 11 different sub-sequences of length 3: {aaa, aan, ana, ann, baa, ban, bna, bnn, naa, nan, nna}.

For the word "tinnitus", how many different sub-sequences of length 3 does it have?


The answer is 34.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Chew-Seong Cheong
Oct 16, 2014

Since it is a CS problem, I solved it a CS way using Python. No good at it, I did as follows:

  1. Get list a a of all the combinations of the three-letter sequences which is 56 ( = ( 3 8 ) ) (= \left( _3 ^8 \right) ) .
  2. Sort list a a of sequences for ease of checking similar elements. 3, Compile the list b b of sequences without repetitions.
  3. Check the length of list b b (the number of elements in list b b ).

 from itertools import combinations
 a = []
 for c in combinations('tinnitus',3):
      a.append(''.join(c))
 a = sorted(a)
 b = []
 b.append(a[0])
 for i in range(len(a)-1):
     if a[i] != a[i+1]:
         b.append(a[i+1])
 print b, len(b)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...