Computers and Technology

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}.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:30, chastineondre7979
How will you cite information that is common knowledge in your research paper?
Answers: 1
image
Computers and Technology, 22.06.2019 23:30, bri2008
Which of the following is not a symptom of chronic fatigue syndrome
Answers: 2
image
Computers and Technology, 23.06.2019 04:31, legendman27
Jennifer has to set up a network in a factory with an environment that has a lot of electrical interference. which cable would she prefer to use? jennifer would prefer to use because its metal sheath reduces interference.
Answers: 1
image
Computers and Technology, 23.06.2019 07:50, madim1275
Most shops require the technician to enter a starting and ending time on the repair order to track the actual time the vehicle was in the shop and closed out by the office. this time is referred to as _ time ? a. comeback b. ro c. cycle d. lead
Answers: 1
Do you know the correct answer?
Consider the following mergeSortHelper method, which is part of an algorithm to recursively sort an...

Questions in other subjects:

Konu
SAT, 16.11.2020 22:10
Konu
Chemistry, 16.11.2020 22:10
Konu
Computers and Technology, 16.11.2020 22:10
Konu
Mathematics, 16.11.2020 22:10
Konu
Mathematics, 16.11.2020 22:10
Konu
Social Studies, 16.11.2020 22:10