0

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:

  1. Is it really possible to create a recursive function for this type of problem?
  2. If it existed, would it be more or less efficient than the iterative method?
  3. If the number of usable chars would increase, performance would be worse or better?
3
  • To point 2: In which term, memory usage or performance? Commented Oct 25, 2017 at 21:56
  • @harandk mem usage and performance Commented Oct 25, 2017 at 22:43
  • Possible duplicate of Recursive permutation in Java generating wrong result Commented Oct 26, 2017 at 0:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.