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 ?

Respuesta :

The statement possibleIndex--; in line 10 is executed 5 times

From the declaration, we have the following array:

int[] arr = {4, 12, 4, 7, 19, 6};

The length of the array is 6

The iteration in the insertionSort function is meant to be repeated from 1 to n - 1

In this case, we have: 1 to 5 (i.e. 6 - 1)

Hence, the statement possibleIndex--; in line 10 is executed 5 times

Read more about insertion sort at:

https://brainly.com/question/15263760