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

Using java recursion, no loops or scanners......Merge two arrays into one. Write

ID: 3686835 • Letter: U

Question

Using java recursion, no loops or scanners......Merge two arrays into one. Write a method named merge which takes 3 interger array parameters: a, b, and soln. soln is guaranteed to be the size of a.length + b.length. The arrays a and b should be "merged" into one array by alternating elements. Add a 4th parameter, which indicates which element in soln should be updated for a given recursive call of the method.

Examples:

merge({1, 2, 3}, {4, 5, 6}, soln, 0) should end with the following values in soln: {1, 4, 2, 5, 3, 6}

merge({1,2}, {3,4,5}, soln, 0) should end with the following values in soln" {1,3,2,4,5}

Explanation / Answer

public static void merge(int a[], int b[], int c[], int i)
{
int j=i;
int k;
  
if(i<=c.length)
{
k=i/2;
if(k<a.length)
{
c[j]=a[k];
j++;
}
if(k<b.length)
{
c[j]=b[k];
j++;

}

merge(a,b,c,i+2);
}
else return ;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote