Why Time complexity of permutation function is O(n!)
Consider following code. public class Permutations { static int count=0; static void permutations(String str, String prefix){ if(str.length()==0){ System.out.println(prefix); } else{ for(int i=0;i<str.length();i++){ count++; String rem = str.substring(0,i) + str.substring(i+1); permutations(rem, prefix+str.charAt(i)); } } } public static void main(String[] args) { permutations(“abc”, “”); System.out.println(count); } } here the logic, that i think is followed is- it … Read more