[Solved] Combinations of all characters in strings in an arraylist in Java, Set multiplication [closed]


First, no one is supposed to give you the actual code for your homework.

Here is the basic idea on how it looks like conceptually:

This can be done recursively by (pseudo-code of course):

String[] allCombinations(String[] input) {
    if (input is empty) {
        return [ "" ]
    }

    String[] result

    String[] childrenCombinations = allCombinations(input[1:])
    foreach char c in input[0] {
        foreach string s in childrenCombinations {
            result += ( c + s )
        }
    }
    return result
}

Of course this is a very naive recursive logic with a lot of unnecessary object creation. However it give you an idea how the algorithm looks like. You may think of area of optimization after you understand the logic

5

solved Combinations of all characters in strings in an arraylist in Java, Set multiplication [closed]