Question: What is the time complexity for these two programs and why is that time complexity? A . ) public static void printPermutations ( char [

What is the time complexity for these two programs and why is that time complexity?
A.)
public static void printPermutations(char[] arr, int index){
if (index == arr.length -1){
System.out.println(new String(arr));
}else{
for (int i = index; i < arr.length; i++){
swap(arr, index, i);
printPermutations(arr, index +1);
swap(arr, index, i);
}
}
}
B.)
public static void swap(char[] arr, int i1, int i2){
char temp = arr[i1];
arr[i1]= arr[i2];
arr[i2]= temp;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!