subject
Engineering, 09.04.2020 17:10 anashaye

Consider the following mergeSortHelper method, which is part of an algorithm to recursively sort an array of integers.

/** Precondition: (arr. length == 0 or 0 <= from <= to <= arr. length)

* arr. length == temp. length

*/

public static void mergeSortHelper(int[] arr, int from, int to, int[] temp)

{

if (from < to)

{

int middle = (from + to) / 2;

mergeSortHelper(arr, from, middle, temp);

mergeSortHelper(arr, middle + 1, to, temp);

merge(arr, from, middle, to, temp);

}

}

The merge method is used to merge two halves of an array (arr[from] through arr[middle], inclusive, and arr[middle + 1] through arr[to], inclusive) when each half has already been sorted into ascending order. For example, consider the array arr1, which contains the values {1, 3, 5, 7, 2, 4, 6, 8}. The lower half of arr1 is sorted in ascending order (elements arr1[0] through arr1[3], or {1, 3, 5, 7}), as is the upper half of arr1 (elements arr1[4] through arr1[7], or {2, 4, 6, 8}). The array will contain the values {1, 2, 3, 4, 5, 6, 7, 8} after the method call merge(arr1, 0, 3, 7, temp). The array temp is a temporary array declared in the calling program.

Consider the following code segment, which appears in a method in the same class as mergeSortHelper and merge.

int[] arr1 = {9, 1, 3, 5, 4};

int[] temp = new int[arr1.length];

mergeSortHelper(arr1, 0, arr1.length - 1, temp);

Which of the following represents the arrays merged the first time the merge method is executed as a result of the code segment above?

A. {9} and {1} are merged to form {1, 9}.
B. {1, 9} and {3} are merged to form {1, 3, 9}.
C. {1, 9} and {5, 4} are merged to form {1, 4, 5, 9}.
D. {1, 3, 9} and {5} are merged to form {1, 3, 5, 9}.
E. {1, 3, 9} and {4, 5} are merged to form {1, 3, 4, 5, 9}.

ansver
Answers: 1

Another question on Engineering

question
Engineering, 03.07.2019 14:10
Line joining liquid phase with liquid and solid phase mixture is known as: a) liquidus b) solidus c) tie line d) none of the mentioned
Answers: 2
question
Engineering, 04.07.2019 18:10
Abrake has a normal braking torque of 2.8 kip in and heat-dissipating cast-iron surfaces whose mass is 40 lbm. suppose a load is brought to rest in 8.0 s from an initial angular speed of 1600 rev/min using the normal braking torque; estimate the temperature rise of the heat dissipating surfaces.
Answers: 3
question
Engineering, 04.07.2019 18:10
Ariver flows from north to south at 8 km/h. a boat is to cross this river from west to east at a speed of 20 km/h (speed of the boat with respect to the earth/ground). at what angle (in degrees) must the boat be pointed upstream such that it will proceed directly across the river (hint: find the speed of the boat with respect to water/river)? a 288 b. 21.8 c. 326 d. 30.2
Answers: 3
question
Engineering, 04.07.2019 18:10
Afull journal bearing has a journal diameter of 27 mm, with a unilateral tolerance of -0.028 mm. the bushing bore has a diameter of 27.028 mm and a unilateral tolerance of 0.04 mm. the l/d ratio is 0.5. the load is 1.3 kn and the journal runs at 1200 rev/min. if the average viscosity is 50 mpa-s, find the minimum film thickness, the power loss, and the side flow for the minimum clearance assembly.
Answers: 1
You know the right answer?
Consider the following mergeSortHelper method, which is part of an algorithm to recursively sort an...
Questions
question
Mathematics, 27.08.2019 06:50
Questions on the website: 13722363