Task - 1: Write a java program (IntegerMergeSort.java) to implement the Merge Sort algorithm to sort the integer array. Your program will have the following method signature: ● ● Following is the Merge Sort Algorithm MERGE-SORT(A, p,r) if p≥r 1 2 3 q = [(p+r)/2] 4 MERGE-SORT(A, p, q) 5 MERGE-SORT (A, q + 1,r) 6 // Merge A[p:q] and A[q +1:r] into A[p:r]. 7 MERGE(A, p, q,r) MERGE(A, p, q,r) 1 n₁ = q-p+1 2 7 8 public void mergeSort(int[] A, int lowerBound, int upperBound) public void merge(int[] A, int lowerBound, int midPoint, int upperBound) Where p and r represent lower (starting index) and upper (ending index) bounds of array A respectively. The Merge Sort calls the following Merge Algorithm that accepts q as the mid of the array along with p and r: 9 10 11 12 13 14 15 16 17 return nR=r-q 3 let L[0:n - 1] and 4 for i = 0 to n-1 // copy A[p:q] into L[0:n, -1] 5 L[i] = A[p + i] 6 for j = 0 ton R-1 // copy A[q +1:r] into R[0:nR-1] R[j] = A[q+j+ 1] 20 21 22 23 24 25 26 27 i = 0 if L[i] ≤ R[j] // zero or one element? A[k] = L[i] i=i+1 j=0 k = p // As long as each of the arrays L and R contains an unmerged element, // copy the smallest unmerged element back into A[p:r]. while i
Task - 1: Write a java program (IntegerMergeSort.java) to implement the Merge Sort algorithm to sort the integer array. Your program will have the following method signature: ● ● Following is the Merge Sort Algorithm MERGE-SORT(A, p,r) if p≥r 1 2 3 q = [(p+r)/2] 4 MERGE-SORT(A, p, q) 5 MERGE-SORT (A, q + 1,r) 6 // Merge A[p:q] and A[q +1:r] into A[p:r]. 7 MERGE(A, p, q,r) MERGE(A, p, q,r) 1 n₁ = q-p+1 2 7 8 public void mergeSort(int[] A, int lowerBound, int upperBound) public void merge(int[] A, int lowerBound, int midPoint, int upperBound) Where p and r represent lower (starting index) and upper (ending index) bounds of array A respectively. The Merge Sort calls the following Merge Algorithm that accepts q as the mid of the array along with p and r: 9 10 11 12 13 14 15 16 17 return nR=r-q 3 let L[0:n - 1] and 4 for i = 0 to n-1 // copy A[p:q] into L[0:n, -1] 5 L[i] = A[p + i] 6 for j = 0 ton R-1 // copy A[q +1:r] into R[0:nR-1] R[j] = A[q+j+ 1] 20 21 22 23 24 25 26 27 i = 0 if L[i] ≤ R[j] // zero or one element? A[k] = L[i] i=i+1 j=0 k = p // As long as each of the arrays L and R contains an unmerged element, // copy the smallest unmerged element back into A[p:r]. while i
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 4 images