Question: Consider the following correct implementation of the insertion sort algorithm. public static void insertionSort ( int [ ] elements ) { for ( int j

Consider the following correct implementation of the insertion sort algorithm.
public static void insertionSort(int[] elements)
{
for (int j =1; j < elements.length; j++)
{
int temp = elements[j];
int possibleIndex = j;
while (possibleIndex >0 && temp < elements[possibleIndex -1])
{
elements[possibleIndex]= elements[possibleIndex -1];
possibleIndex--; // Line 10
}
elements[possibleIndex]= temp;
}
}
The following declaration and method call appear in a method in the same class as insertionSort.
int[] arr ={4,12,4,7,19,6};
insertionSort(arr);
How many times is the statement possibleIndex--; in line 10 of the method executed as a result of the call to insertionSort ?

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!