Computers and Technology

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 ?

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 08:10, autumnguidry1622
Technician a says that if a valve is open when a piston rises to the very top of a cylinder, the piston may actually strike the valve head and cause serious engine damage. technician b says if the camshaft is located in the engine block, then the engine is called an overhead valve engine, ohv engine, or an in-block camshaft. who is right? a. b only b. both a and b c. a only d. neither a nor b
Answers: 3
image
Computers and Technology, 22.06.2019 12:00, dani19cano
The following function returns a string of length n whose characters are all 'x'. give the order of growth (as a function of n) of the running time. recall that concatenating two strings in java takes time proportional to the sum of their lengths. public static string f(int n) { if (n == 0) return ""; if (n == 1) return "x"; return f(n/2) + f(n - n/2); } options: a) constant b) logarithmic c) linear d) linearithmic e)quadratic f)cubic g) exponential
Answers: 2
image
Computers and Technology, 22.06.2019 18:30, Akkenson17871
The "instance" relationship shows that something is an object of a
Answers: 1
image
Computers and Technology, 22.06.2019 21:30, Cheflulu5727
Write a function named printfloatrepresentation(float number) that will print the floating point representation of a number using the format given below. (sign bit) exponent in binary (assumed bit).significandfor example if the number passed an argument is 71 yourprogram should print (0) 10000101 (1).00011100000000000000000similarl y if the number passed to the function as argument is -71 the program should print (1) 10000101 (1).00011100000000000000000
Answers: 3
Do you know the correct answer?
Consider the following correct implementation of the insertion sort algorithm. public static void i...

Questions in other subjects: