Question: what is the best, worse, and average time complexity? Explain why for each. public static void selectionSort ( int [ ] arr ) { int

what is the best, worse, and average time complexity? Explain why for each.
public static void selectionSort(int[] arr){
int n = arr.length;
for (int i =0; i < n -1; i++){
System.out.print(arr[i]+":\t ");
int min_idx = i;
for (int j = i +1; j < n; j++){
System.out.print(arr[j]+",");
if (arr[j]< arr[min_idx]){
min_idx = j;
}
}
int temp = arr[i];
arr[i]= arr[min_idx];
arr[min_idx]= temp;
System.out.println();
}
}

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!