Question: Consider the following implementation of the insertion sort algorithm for an Array of doubles. public static int insertSort ( double [ ] arr ) {

Consider the following implementation of the insertion sort algorithm for an Array of doubles.
public static int insertSort(double[] arr){
int count =0;
for (int i =1; i < arr.length; i++){
double val = arr[i];
int j;
for (j = i -1; j >=0; j--){
count++;
if (arr[j]> val){
arr[j +1]= arr[j];
} else {
break;
}
}
arr[j +1]= val;
}
return count;
}
The method returns an int which represents a statement execution count. What will this value be when the method returns if the parameter list is the array {3.3,4.7,1.2,4.1}:

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 Databases Questions!