subject

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: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 10:30
Would a ps4 wired controller work on an xbox one
Answers: 1
question
Computers and Technology, 24.06.2019 01:30
How can you make your column headings stand out?
Answers: 1
question
Computers and Technology, 24.06.2019 05:30
Why is hard disk space important to an audio engineer? why are usb ports and firewire ports useful for an audio engineer? explain in 2-3 sentences. (3.0 points) here's a list of different audio software: ableton live apple inc.'s garageband apple inc.'s logic studio digidesign's pro tools propellerhead sofware's reason sony creative software's acid pro steinberg cubase steinberg nuendo choose one of the software programs listed above, and then go to that software program's web site. read about what the software program is used for, and then write 4-5 sentences about what you learned. (10.0 points) which type of software license is the most limiting? why? explain in 2-3 sentences. (3.0 points) when sending a midi channel voice message, how can you control the volume of the sound? explain in 2-3 sentences. (4.0 points)
Answers: 1
question
Computers and Technology, 24.06.2019 13:30
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. the program should output the average high, average low, and the highest and lowest temper- atures for the year. your program must consist of the following functions: a. function getdata: this function reads and stores data in the two- dimensional array. b. function averagehigh: this function calculates and returns the average high temperature for the year. c. function averagelow: this function calculates and returns the aver- age low temperature for the year. d. function indexhightemp: this function returns the index of the highest high temperature in the array. e. function indexlowtemp: this function retur
Answers: 3
You know the right answer?
Consider the following mergeSortHelper method, which is part of an algorithm to recursively sort an...
Questions
question
Mathematics, 03.12.2021 21:00
Questions on the website: 13722363