[Math] Count of all possible combinations of length $K$ for a given string of $N$ letters

combinatoricspermutations

I need to find the count of all possible combinations of length $K$ for a given string $N$. The characters cannot repeat.

For example, if the given string is $$a,b,c,d,\quad N=4$$

The possible number of combinations of length $K=2$ will be $12$:
$$
ab,ac,ad,bc,bd,cd,ba,ca,cb,da,dc,db
$$

The possible number of combinations of length $K=3$ will be $24$:
$$
abc,abd,acb,acd,adb,adc,bac,bad,bcd,bca,bda,bdc,cab,cad,cba,cbd,cda,cdb,dab,dac,dba,dbc,dca,dcb
$$

Is the formula $\dfrac{N!}{(N-K)!}$ correct?

Best Answer

Your formula is correct, and here is why:

There are $\displaystyle{N \choose K} = \frac{N!}{(N-K)!K!}$ ways to pick a set of $K$ non-repeating characters out of $N$ characters.

Also, once you have those $K$ different characters picked, you can order them in $K!$ ways.

So, there are

$$\frac{N!}{(N-K)!K!} \cdot K! = \frac{N!}{(N-K)!}$$

possible strings of $K$ different characters chosen from a group of $N$ characters.