I have 3 char "abc".
All combinations with these 3 characters are 3^3 = 27:
aaa, aab, aac, aba, ... etc.
I write a pseudo-code to print all of these combinations:
string dictionary[3] = {"a", "b", "c"};
string str[3];
for (i=0;i<3;++i) {
str[0]=dictionary[i];
for (j=0;j<3;++j) {
str[1]=dictionary[j];
for(k=0;k<3;++k) {
str[2]=dictionary[k];
println(str);
}
}
}
Now, I can see that all loops start at 0 and end at 2. So I thought there was a way to make this function as a recursive function, although in fact no basic step can be distinguished. So, i asked myself:
- Is it really possible to create a recursive function for this type of problem?
- If it existed, would it be more or less efficient than the iterative method?
- If the number of usable chars would increase, performance would be worse or better?