My objective is to find all the permutations of a String. And after some quick search, I found a neat way to find all the permutations of the String. ie
private static void permutation(String prefix, String str)
{
int n = str.length();
if (n == 0)
System.out.println(prefix);
else
{
for (int i = 0; i < n; i++)
permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
}
}
and I believe the complexity of this method is O(n!) (correct me if I am wrong). And my question is: Can I tweak this anymore to improve the efficiency of this? Or is there a better alternative to generate all the permutations?