Question: This is Java Code of MergeSort. I tried to run it but it throws this errors Exception in thread main java.lang.ArrayIndexOutOfBoundsException: 7 at Merge.Merge(Merge.java:31) at

This is Java Code of MergeSort. I tried to run it but it throws this errors

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 at Merge.Merge(Merge.java:31) at Merge.MergeSort(Merge.java:11) at Merge.MergeSort(Merge.java:10) at Merge.main(Merge.java:55)

Please Help me to fix it. Below are the code

import java.util.Arrays;

public class Merge {

public static void MergeSort( int [] A, int p, int r){ if( p < r ) { int q = (int) Math.floor((p+r)/2); MergeSort(A,p,q); MergeSort(A,q + 1,r); Merge(A,p,q,r); } }

public static void Merge( int [] A, int p,int q, int r){ int n1 = q - p +1; int n2 = r - q; int [] left= new int [n1+1 ]; int [] right = new int [n2+1 ]; for(int i = 0;i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!