Share via:

Character Combinations in The Alphabet

How to calculate the number of permutations in the alphabet. Also include a short table over permutations.


Edited: 2020-06-06 02:34

Sometimes it may be useful to know the number of character combinations in the alphabet for a given string length. We can calculate it by knowing the number of letters in the alphabet; since the English alphabet has 26 letters, we multiply 26*26=676 to find the number of letter combinations for a 2-character string.

Note. If you are trying to generate permutations of the alphabet progrematically, then beware that the total possible combinations will increase exponentially, and potentially exhaust system resources rather quickly. I have personally crashed my computer and lost work from fooling around with this stuff.

You probably should not generate permutations dynamically in programs. It may be better to keep a database or file with pre-generated permutations.

Here is table containing the number of possible letter combinations:

2 26*26 or 26^3 676alphabet-two-letter-combinations.txt2.1 kb
3 26*26*26 or 26^3 17.576alphabet-three-letter-combinations.txt70.4 kb
4 26*26*26*26 or 26^4 456.976alphabet-four-letter-combinations.txt2.3 mb
5 26*26*26*26*26 or 26^5 11.881.376alphabet-five-letter-combinations.txt71.3 mb
6 26*26*26*26*26*26 or 26^6 308.915.776Nope... Not doing it.. Do it yourself!

Note. Each permutation in the files above is followed by a single line break (\n).

Generate permutations from terminal

We do not necessarily need to create an algorithm for generating permutations. In Linux, it is also possible to generate permutations from a terminal with this very simple syntax: {a..z}.

To output all possible permutations of a two-letter string using the 26 letters of the alphabet:

echo {a..z}{a..z}

If you want to handle this in another programming language, such as PHP, you can create bash script and place it in usr/local/bin/permutations_2x.sh:

echo {a..z}{a..z}

This can then be called from PHP with shell_exec:

echo shell_exec('permutations_2x.sh');

Since I use PHP a lot, I find shell_exec to be useful for interacting with other programs at times.

Why are permutations interesting?

I have no idea. But, I personally had a need to generate all possible permutations of a two-letter string consisting of the 26 letters of the alphabet.

A two-letter string gives me 676 possible combinations, which should be more than enough to satisfy my needs. I was thinking that I wanted to try it out for shortening long text strings in order to save bandwidth for mobile users. It was also a nice little programming challenge to solve.

The alphabet is also an ideal candidate to practice on; once you have written an algorithm that works on the alphabet, you should also be able to use it on longer text strings.