subject

Consider the following mergeSortHelper method, which is part ofan 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 anarray (arr[from] througharr[middle], inclusive, and arr[middle + 1]through arr[to], inclusive) when each half hasalready been sorted into ascending order. For example, consider thearray arr1, which contains the values {1, 3, 5, 7,2, 4, 6, 8}. The lower half of arr1 is sorted inascending order (elements arr1[0] througharr1[3], or {1, 3, 5, 7}), as isthe upper half of arr1 (elements arr1[4] througharr1[7], or {2, 4, 6, 8}). Thearray will contain the values {1, 2, 3, 4, 5, 6, 7, 8} after themethod call merge(arr1, 0, 3, 7, temp). The arraytemp is a temporary array declared in the calling program.

Consider the following code segment, which appears in a methodin 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 firsttime the merge method is executed as a result of the code segmentabove?

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 toform {1, 4, 5, 9}.

D. {1, 3, 9} and {5} are merged toform {1, 3, 5, 9}.

E. {1, 3, 9} and {4, 5} are merged toform {1, 3, 4, 5, 9}.

ansver
Answers: 1

Another question on Advanced Placement (AP)

question
Advanced Placement (AP), 22.06.2019 04:00
Avery is using the experssion builder shown below. which steps will allow avery to add the expression “[ingitemordid]< 100” to the expression builder panel? a. select “qryordersandamoumt,” select “ingitemordid,” then click on its value property, drag it to the panel, and type “< 100” in the panel after the syntax for the field. b. select “qryordersandamoumt,” double-click on “ingitemordid,” drag it to the panel, and type “< 100” in the panel after the syntax for the field. c. select “qryordersandamoumt,” select “ingitemordid,” then click on its value property, drag both to the panel, and type “< 100” in the panel after the syntax for the field. d. select “qryordersandamoumt,” select “ingitemordid,” double-click on its value property, drag it to the panel, and type “< 100” in the panel after the syntax for the field.
Answers: 3
question
Advanced Placement (AP), 22.06.2019 20:30
How did the large influx of immigrants change america?
Answers: 1
question
Advanced Placement (AP), 23.06.2019 08:20
Who wants free points + brainliest? answer this question correctly and you shall receive if you're caught driving with you could be punished with up to a year in jail and be fined up to $1,000. a. a suspended driver license or license plate b. an intoxicated minor passenger c. headphones covering both ears d. a broken taillight or headlight
Answers: 1
question
Advanced Placement (AP), 23.06.2019 18:30
Ill give you free brainliest + free points if you answer this drvers ed question correctly! when merging, yield to traffic a. already on the road you're joining b. on your right side only c. if it's going slower than you d. if it's going the same speed as you
Answers: 2
You know the right answer?
Consider the following mergeSortHelper method, which is part ofan algorithm to recursively sort an a...
Questions
Questions on the website: 13722362