How to get all permutations of a variable-length word

893 Views Asked by At

I need to find all permutations of a set of letters (word) with following parameters:

  • Word lengths $\ell = [1, 20]$

  • Alphabet $A = \{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t\} \Rightarrow \lvert a\rvert=20$

Each letter can only appear once in a word. For each word length in $\ell$ all combinations of all letters must be found.

The letter order in a word does not matter. This would be the same: $abcd = dacb$

This simplified problem formulation is needed for implementing a SVM (support vector machine) where the best combination of $20$ different classes must be teached / learned. I have a iterative programmatic solution in mind but this keeps confusing me.

Is there anyone here who can master this?

Regards

1

There are 1 best solutions below

1
On BEST ANSWER

If I'm understanding you correctly, the problem is essentially equivalent to finding the number of distinct subsets of $\;A=\{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t\},\;$ minus the empty set (word length $\mathcal l=0$) : i.e., the number of words you can find under the given criteria is given by $$|P(A)| - 1 = 2^{|A|}-1 = 2^{20}-1 = 1048575$$