How to get all permutations of a variable-length word

$\begingroup$

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

$\endgroup$

1 Answer

$\begingroup$

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$$

$\endgroup$ 1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like