How to find permutation of k in a given length?

前端 未结 6 680
小鲜肉
小鲜肉 2020-12-05 17:01

How can I find the permutations of k in a given length?

For example:

The word cat has 3 letters: How can I find all the permutations of 2 in the

6条回答
  •  粉色の甜心
    2020-12-05 17:33

    If I'm not mistaken, this problem can be solved by combinadics too, as on http://en.wikipedia.org/wiki/Combinadic/, there are reference implementations there too.

    I have used the Java solution (http://docs.google.com/Doc?id=ffffd8c4hm_5fkdr3b/) myself for generating all possible triples from a sequence of numbers, this should be no different.

    I lack the wherewithal to explain the math behind it, but as I understand this is the least complex way to iterate over all possible nCr (i.e. 3C2 for your cat example) choices within a collection.

提交回复
热议问题