Introduction to the Theory of Computation Class Assignment
Program that takes as input an array of distinct characters (e.g. [’a’,’c’,’d’]) and an integer k, and outputs a list of all possible strings consisting of exactly k characters from the input. Each possible string should appear only once in the output.
Example: Input = [a, b, c] k = 3
Output:
-
aaa
-
aab
-
aba
-
baa
-
aac
-
aca
-
caa
-
abc
-
acb
-
bac
-
cab
-
ccc
-
cca
-
cac
-
acc
-
ccb
-
cbc
-
bcc
-
bbb
-
bba
-
bab
-
abb
-
bbc
-
bcb
-
cbb
-
bca
-
cba
This is just permutations, so for an array of size N and strings of length K, we would have NK possible strings.
In this example the array is of size 3 and k = 3, the number of possible strings of length 3 is 33, or 27. If k = 6, then we can have 36 possible strings, and so on.