Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can any one please give me the code in javaaaa Segment 9.8 introduced you to an

ID: 3859299 • Letter: C

Question

Can any one please give me the code in javaaaa

Segment 9.8 introduced you to an iterative merge sort. This project continues that discussion by proviciliing3 mort.lesiaailts salinguntifW2IKHTyc6xypes. a. If n is a power of 2, as it is in Figure 2, you would merge pairs of individual entries, starting at the beginning of the array. Then you would return to the beginning of the array and merge pairs of twoentry subarrays.Finally, you would merge one pair of four-entry subarrays. Notice that the subarrays in each pair of subarrays contain the same number of entries In general, n might not be a power of 2. After merging a certain number of pairs of subarrays, you might have too few entries left to make up a complete pair of subarrays. In Figure 3a, after more details about the merge steps. merging pairs of single entries, one entry is left over. You then merge one pair of two-entry subarrays, and merge the leftover two-entry subarray with the leftover single entry. Parts b andc of Figure 3 show two other possibilities. Implement an iterative merge sort. Use the algorithm merge that was given in Segment 9.3. A private method that uses merge to merge the pairs of subarrays is useful. After the methood completes its task, you can handle the leftovers that we just described. b. Merging two subarrays requires an additional temporary array. Although you need to use this extra space, you can save much of the time that our earlier merge algorithm spends in copying

Explanation / Answer

package demo;

import java.util.Scanner;

public class DemoTranslation {

public static void main(String[] args) {

int[] lst = new int[50];

int sz;

System.out.print("Enter total number of elements:");

sz = STDIN_SCANNER.nextInt();

System.out.println("Enter the elements:");

for(int uu = 0; uu < sz; uu++) {

lst[uu] = STDIN_SCANNER.nextInt();

}

parts(lst, 0, sz - 1);

System.out.println("After merge sort:");

for(int uu = 0; uu < sz; uu++) {

System.out.print(lst[uu] + " ");

}

}

public static void parts(int[] lst, int lower, int hi) {

int middle;

if(lower < hi) {

middle = (lower + hi) / 2;

parts(lst, lower, middle);

parts(lst, middle + 1, hi);

sortMerge(lst, lower, middle, hi);

}

}

public static void sortMerge(int[] lst, int lower, int middle, int hi) {

int uu, io, lo = 0;

int[] temporary = new int[50];

lo = lo;

uu = lo;

io = middle + 1;

while(lo <= middle && io <= hi) {

if(lst[lo] <= lst[io]) {

temporary[uu] = lst[lo];

lo++;

} else {

temporary[uu] = lst[io];

io++;

}

uu++;

}

if(lo > middle) {

for(int qu = io; qu <= hi; qu++) {

temporary[uu] = lst[qu];

uu++;

}

} else {

for(int qu = lo; qu <= middle; qu++) {

temporary[uu] = lst[qu];

uu++;

}

}

for(int qu = lo; qu <= hi; qu++) {

lst[qu] = temporary[qu];

}

}

public final static Scanner STDIN_SCANNER = new Scanner(System.in);

}